@rockshin/tao-ui 0.0.52 → 0.0.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -106,9 +106,14 @@
|
|
|
106
106
|
padding-inline-end: var(--tao-control-height);
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
:where([data-tao-textarea]:has( > [data-tao-input-count]) textarea) {
|
|
110
|
+
padding-inline-end: calc(var(--tao-textarea-count-width, 0px) + var(--tao-padding-md) +
|
|
111
|
+
var(--tao-padding-xs));
|
|
112
|
+
}
|
|
113
|
+
|
|
109
114
|
[data-tao-textarea] > [data-tao-input-count] {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
115
|
+
position: absolute;
|
|
116
|
+
inset-block-end: var(--tao-padding-xxs);
|
|
117
|
+
inset-inline-end: var(--tao-padding-md);
|
|
113
118
|
}
|
|
114
119
|
|
|
@@ -18,7 +18,9 @@ const textarea_Textarea = /*#__PURE__*/ forwardRef(function(props, ref) {
|
|
|
18
18
|
const resolvedDisabled = disabled ?? ctx.disabled;
|
|
19
19
|
const innerRef = useRef(null);
|
|
20
20
|
const rootRef = useRef(null);
|
|
21
|
+
const countRef = useRef(null);
|
|
21
22
|
const field = useTextControl(props, innerRef);
|
|
23
|
+
const hasCount = null != field.counter;
|
|
22
24
|
useTextControlRef(ref, innerRef, rootRef);
|
|
23
25
|
const [measuredStyle, setMeasuredStyle] = useState();
|
|
24
26
|
const resize = useCallback(()=>{
|
|
@@ -57,20 +59,38 @@ const textarea_Textarea = /*#__PURE__*/ forwardRef(function(props, ref) {
|
|
|
57
59
|
resize,
|
|
58
60
|
field.value
|
|
59
61
|
]);
|
|
62
|
+
useLayoutEffect(()=>{
|
|
63
|
+
if (!hasCount) return;
|
|
64
|
+
const count_0 = countRef.current;
|
|
65
|
+
const root = rootRef.current;
|
|
66
|
+
if (!count_0 || !root) return;
|
|
67
|
+
const update = ()=>{
|
|
68
|
+
root.style.setProperty('--tao-textarea-count-width', `${count_0.offsetWidth}px`);
|
|
69
|
+
};
|
|
70
|
+
update();
|
|
71
|
+
const observer = new ResizeObserver(update);
|
|
72
|
+
observer.observe(count_0);
|
|
73
|
+
return ()=>{
|
|
74
|
+
observer.disconnect();
|
|
75
|
+
root.style.removeProperty('--tao-textarea-count-width');
|
|
76
|
+
};
|
|
77
|
+
}, [
|
|
78
|
+
hasCount
|
|
79
|
+
]);
|
|
60
80
|
useLayoutEffect(()=>{
|
|
61
81
|
const el_0 = innerRef.current;
|
|
62
82
|
if (!el_0 || !autoSize) return;
|
|
63
83
|
let width;
|
|
64
84
|
let frame = 0;
|
|
65
|
-
const
|
|
85
|
+
const observer_0 = new ResizeObserver(([entry])=>{
|
|
66
86
|
if (entry.contentRect.width === width) return;
|
|
67
87
|
width = entry.contentRect.width;
|
|
68
88
|
cancelAnimationFrame(frame);
|
|
69
89
|
frame = requestAnimationFrame(resize);
|
|
70
90
|
});
|
|
71
|
-
|
|
91
|
+
observer_0.observe(el_0);
|
|
72
92
|
return ()=>{
|
|
73
|
-
|
|
93
|
+
observer_0.disconnect();
|
|
74
94
|
cancelAnimationFrame(frame);
|
|
75
95
|
};
|
|
76
96
|
}, [
|
|
@@ -125,7 +145,8 @@ const textarea_Textarea = /*#__PURE__*/ forwardRef(function(props, ref) {
|
|
|
125
145
|
className: classNames?.clear,
|
|
126
146
|
style: styles?.clear
|
|
127
147
|
}),
|
|
128
|
-
|
|
148
|
+
hasCount && /*#__PURE__*/ jsx("span", {
|
|
149
|
+
ref: countRef,
|
|
129
150
|
"data-tao-input-count": "",
|
|
130
151
|
"data-tao-exceeded": field.exceeded || void 0,
|
|
131
152
|
className: classNames?.count,
|