@doist/reactist 28.1.1 → 28.1.2

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.
@@ -2355,31 +2355,13 @@ const TextArea = /*#__PURE__*/React__namespace.forwardRef(function TextArea(_ref
2355
2355
  const containerRef = React__namespace.useRef(null);
2356
2356
  const internalRef = React__namespace.useRef(null);
2357
2357
  const combinedRef = useCallbackRef.useMergeRefs([ref, internalRef]);
2358
+ useAutoExpand({
2359
+ value,
2360
+ autoExpand,
2361
+ containerRef,
2362
+ internalRef
2363
+ });
2358
2364
  const textAreaClassName = classNames__default["default"]([autoExpand ? modules_2728c236.disableResize : null, disableResize ? modules_2728c236.disableResize : null]);
2359
- React__namespace.useEffect(function setupAutoExpand() {
2360
- const containerElement = containerRef.current;
2361
-
2362
- function handleAutoExpand(value) {
2363
- if (containerElement) {
2364
- containerElement.dataset.replicatedValue = value;
2365
- }
2366
- }
2367
-
2368
- function handleInput(event) {
2369
- handleAutoExpand(event.currentTarget.value);
2370
- }
2371
-
2372
- const textAreaElement = internalRef.current;
2373
-
2374
- if (!textAreaElement || !autoExpand) {
2375
- return undefined;
2376
- } // Apply change initially, in case the text area has a non-empty initial value
2377
-
2378
-
2379
- handleAutoExpand(textAreaElement.value);
2380
- textAreaElement.addEventListener('input', handleInput);
2381
- return () => textAreaElement.removeEventListener('input', handleInput);
2382
- }, [autoExpand]);
2383
2365
  return /*#__PURE__*/React__namespace.createElement(BaseField, {
2384
2366
  variant: variant,
2385
2367
  id: id,
@@ -2417,6 +2399,50 @@ const TextArea = /*#__PURE__*/React__namespace.forwardRef(function TextArea(_ref
2417
2399
  });
2418
2400
  });
2419
2401
 
2402
+ function useAutoExpand({
2403
+ value,
2404
+ autoExpand,
2405
+ containerRef,
2406
+ internalRef
2407
+ }) {
2408
+ const isControlled = value !== undefined;
2409
+ React__namespace.useEffect(function setupAutoExpandWhenUncontrolled() {
2410
+ const textAreaElement = internalRef.current;
2411
+
2412
+ if (!textAreaElement || !autoExpand || isControlled) {
2413
+ return undefined;
2414
+ }
2415
+
2416
+ const containerElement = containerRef.current;
2417
+
2418
+ function handleAutoExpand(value) {
2419
+ if (containerElement) {
2420
+ containerElement.dataset.replicatedValue = value;
2421
+ }
2422
+ }
2423
+
2424
+ function handleInput(event) {
2425
+ handleAutoExpand(event.currentTarget.value);
2426
+ } // Apply change initially, in case the text area has a non-empty initial value
2427
+
2428
+
2429
+ handleAutoExpand(textAreaElement.value);
2430
+ textAreaElement.addEventListener('input', handleInput);
2431
+ return () => textAreaElement.removeEventListener('input', handleInput);
2432
+ }, [autoExpand, containerRef, internalRef, isControlled]);
2433
+ React__namespace.useEffect(function setupAutoExpandWhenControlled() {
2434
+ if (!isControlled) {
2435
+ return;
2436
+ }
2437
+
2438
+ const containerElement = containerRef.current;
2439
+
2440
+ if (containerElement) {
2441
+ containerElement.dataset.replicatedValue = value;
2442
+ }
2443
+ }, [value, containerRef, isControlled]);
2444
+ }
2445
+
2420
2446
  function getInitials(name) {
2421
2447
  var _initials;
2422
2448