@mpen/react-basic-inputs 0.1.4 → 0.1.5

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/bundle.cjs CHANGED
@@ -218,7 +218,6 @@ function TextInput({formatOnChange = collapseWhitespace, ...otherProps}) {
218
218
  const TextArea = React.forwardRef((function TextArea({onInput, style, ...rest}, fwdRef) {
219
219
  const ref = React.useRef(null);
220
220
  const [height, setHeight] = React.useState("auto");
221
- React.useImperativeHandle(fwdRef, (() => ref.current));
222
221
  const adjustHeight = () => {
223
222
  const textarea = ref.current;
224
223
  if (!textarea) return;
@@ -227,6 +226,10 @@ const TextArea = React.forwardRef((function TextArea({onInput, style, ...rest},
227
226
  setHeight(newHeight);
228
227
  textarea.style.height = newHeight;
229
228
  };
229
+ React.useImperativeHandle(fwdRef, (() => ({
230
+ element: ref.current,
231
+ resize: adjustHeight
232
+ })), [ setHeight, ref.current ]);
230
233
  const input = useEventHandler((ev => {
231
234
  adjustHeight();
232
235
  onInput?.(ev);
@@ -235,6 +238,7 @@ const TextArea = React.forwardRef((function TextArea({onInput, style, ...rest},
235
238
  adjustHeight();
236
239
  }), []);
237
240
  return jsxRuntime.jsx("textarea", {
241
+ rows: 1,
238
242
  ...rest,
239
243
  style: {
240
244
  ...style,
package/dist/bundle.mjs CHANGED
@@ -216,7 +216,6 @@ function TextInput({formatOnChange = collapseWhitespace, ...otherProps}) {
216
216
  const TextArea = forwardRef((function TextArea({onInput, style, ...rest}, fwdRef) {
217
217
  const ref = useRef(null);
218
218
  const [height, setHeight] = useState("auto");
219
- useImperativeHandle(fwdRef, (() => ref.current));
220
219
  const adjustHeight = () => {
221
220
  const textarea = ref.current;
222
221
  if (!textarea) return;
@@ -225,6 +224,10 @@ const TextArea = forwardRef((function TextArea({onInput, style, ...rest}, fwdRef
225
224
  setHeight(newHeight);
226
225
  textarea.style.height = newHeight;
227
226
  };
227
+ useImperativeHandle(fwdRef, (() => ({
228
+ element: ref.current,
229
+ resize: adjustHeight
230
+ })), [ setHeight, ref.current ]);
228
231
  const input = useEventHandler((ev => {
229
232
  adjustHeight();
230
233
  onInput?.(ev);
@@ -233,6 +236,7 @@ const TextArea = forwardRef((function TextArea({onInput, style, ...rest}, fwdRef
233
236
  adjustHeight();
234
237
  }), []);
235
238
  return jsx("textarea", {
239
+ rows: 1,
236
240
  ...rest,
237
241
  style: {
238
242
  ...style,
@@ -1,4 +1,8 @@
1
1
  /// <reference types="react" />
2
- import { OverrideProps } from '../types/utility';
2
+ import { HtmlTextAreaElement, OverrideProps, VoidFn } from '../types/utility';
3
+ export type TextAreaRef = {
4
+ element: HtmlTextAreaElement;
5
+ resize: VoidFn;
6
+ };
3
7
  export type TextAreaProps = OverrideProps<'textarea', {}>;
4
- export declare const TextArea: import("react").ForwardRefExoticComponent<Omit<Omit<import("react").DetailedHTMLProps<import("react").TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement>, "ref">, never> & import("react").RefAttributes<HTMLTextAreaElement>>;
8
+ export declare const TextArea: import("react").ForwardRefExoticComponent<Omit<Omit<import("react").DetailedHTMLProps<import("react").TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement>, "ref">, never> & import("react").RefAttributes<TextAreaRef>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpen/react-basic-inputs",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "packageManager": "yarn@3.5.0",
5
5
  "exports": {
6
6
  ".": {