UIComponentsReact
A text field of several lines whose height follows its text between a smallest and a largest number of rows.
Built on the headless Textarea Autosize.See its API in Docs
Rendered by React 19.3.1
Installation
npx shadcn@4.23.0 add https://hamur.dev/r/react/textarea-autosize.jsonIt also adds utils. The app needs its setup first: Installation.
Usage
Use TextareaAutosize where a Textarea would go and give it minRows and maxRows (by default one row and no limit); past maxRows it scrolls. It takes the textarea element's attributes but rows, which it writes itself, and onHeightChange reports each new height (Vue: the heightChange emit; Angular: the heightChange output). After a value written from script, updateHeight() sizes it again (React, Vue, Svelte and Solid: actionsRef; Angular: #textarea="uiTextareaAutosize"). Name the field with a Field label or aria-label. The sizing, the Field integration and the form value come from the headless Textarea Autosize.
import { TextareaAutosize } from '@/components/ui/textarea-autosize'Examples
Default
A message field in a Field, between two and six rows, with two lines of text and a description.
It is the Textarea's box without its CSS sizing, since the component chooses how it sizes, and with resize-none, since a dragged height would be overwritten. min-h-16 stays as the app's smallest height while minRows is one; a minRows above one replaces it. The text and placeholder colours are the Textarea's, the placeholder at least 4.5:1 against the field's background in every preset theme, light and dark (WCAG 1.4.3); one row is over 24 px tall (WCAG 2.5.8), and it shows the focus ring (WCAG 2.4.7). This item takes Base UI's component ID as its slug.
API reference
The styled parts pass every prop to the headless part they wrap and add classes. The props, data attributes and keyboard are on Textarea Autosize's API reference.