@ladder-ui/textarea 0.2.0 → 0.3.0

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.
package/dist/index.js CHANGED
@@ -4,13 +4,20 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var jsxRuntime = require('react/jsx-runtime');
6
6
  var concatClassNames = require('@ladder-ui/core/concatClassNames');
7
+ var react = require('react');
7
8
 
8
9
  function Textarea({ ref, className, size = "md", status = "default", fullWidth = true, resize = "vertical", autoResize = false, disabled, readOnly, onInput, style, ...props }) {
9
10
  const ariaInvalid = props["aria-invalid"] ?? (status === "error" ? true : undefined);
11
+ // Track pending animation frame so rapid typing only triggers one resize per frame
12
+ const rafRef = react.useRef(0);
10
13
  return (jsxRuntime.jsx("textarea", { ref: ref, className: concatClassNames("lui-textarea", `lui-textarea--${size}`, status !== "default" && `lui-textarea--${status}`, !autoResize && resize !== "vertical" && `lui-textarea--resize-${resize}`, fullWidth && "lui-textarea--full-width", className), disabled: disabled, readOnly: readOnly, "aria-invalid": ariaInvalid, onInput: (e) => {
11
14
  if (autoResize) {
12
- e.currentTarget.style.height = "auto";
13
- e.currentTarget.style.height = `${e.currentTarget.scrollHeight}px`;
15
+ const el = e.currentTarget;
16
+ cancelAnimationFrame(rafRef.current);
17
+ rafRef.current = requestAnimationFrame(() => {
18
+ el.style.height = "auto";
19
+ el.style.height = `${el.scrollHeight}px`;
20
+ });
14
21
  }
15
22
  onInput?.(e);
16
23
  }, style: autoResize ? { overflow: "hidden", resize: "none", ...style } : style, ...props }));
package/dist/index.mjs CHANGED
@@ -1,12 +1,19 @@
1
1
  import { jsx } from 'react/jsx-runtime';
2
2
  import concatClassNames from '@ladder-ui/core/concatClassNames';
3
+ import { useRef } from 'react';
3
4
 
4
5
  function Textarea({ ref, className, size = "md", status = "default", fullWidth = true, resize = "vertical", autoResize = false, disabled, readOnly, onInput, style, ...props }) {
5
6
  const ariaInvalid = props["aria-invalid"] ?? (status === "error" ? true : undefined);
7
+ // Track pending animation frame so rapid typing only triggers one resize per frame
8
+ const rafRef = useRef(0);
6
9
  return (jsx("textarea", { ref: ref, className: concatClassNames("lui-textarea", `lui-textarea--${size}`, status !== "default" && `lui-textarea--${status}`, !autoResize && resize !== "vertical" && `lui-textarea--resize-${resize}`, fullWidth && "lui-textarea--full-width", className), disabled: disabled, readOnly: readOnly, "aria-invalid": ariaInvalid, onInput: (e) => {
7
10
  if (autoResize) {
8
- e.currentTarget.style.height = "auto";
9
- e.currentTarget.style.height = `${e.currentTarget.scrollHeight}px`;
11
+ const el = e.currentTarget;
12
+ cancelAnimationFrame(rafRef.current);
13
+ rafRef.current = requestAnimationFrame(() => {
14
+ el.style.height = "auto";
15
+ el.style.height = `${el.scrollHeight}px`;
16
+ });
10
17
  }
11
18
  onInput?.(e);
12
19
  }, style: autoResize ? { overflow: "hidden", resize: "none", ...style } : style, ...props }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ladder-ui/textarea",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -47,7 +47,7 @@
47
47
  "sass": "^1.90.0",
48
48
  "tslib": "^2.6.2",
49
49
  "typescript": "^5.3.3",
50
- "@ladder-ui/core": "0.2.0"
50
+ "@ladder-ui/core": "0.3.0"
51
51
  },
52
52
  "peerDependencies": {
53
53
  "@ladder-ui/core": ">=0.0.0",