<UnstyledTextareaAutosize />
is an unstyled multi-line text component for React that adapts to its content.
Use your favourite manager to install the package:
yarn add unstyled-textarea-autosize
npm install unstyled-textarea-autosize --save
import React from "react";
import { UnstyledTextareaAutosize } from "unstyled-textarea-autosize";
export function Example({
value,
onChange,
}: {
value: string;
onChange: (value: string) => void;
}) {
return (
<UnstyledTextareaAutosize
className="example"
value={value}
onValueChange={onChange}
/>
);
}
The component accepts all properties of the intrinsic div
component, including the style
and className
properties. In addition, it accepts the following properties:
readOnly?: boolean
: Content cannot be edited if set totrue
.value?: string
: The current content value of the text component (controlled mode).initialValue?: string
: The initial content value of the text component (uncontrolled mode).onValueChange?: (value: string) => void
: A callback function that is called each time the user edits the content.
A reference to the component provides all attributes of the intrinsic div
DOM element. In addition, it provides the following attribute:
value: string
: The current content value of the text component.
Please use the exported type UnstyledTextareaAutosizeElement
for the reference.
This library is licensed under the MIT license.
We welcome contributions to the unstyled-textarea-autosize
library. To contribute, simply open a pull request with your changes.