Autosize Textarea
Overview
A textarea that automatically grows and shrinks to fit its content.
This form component is intended for interfaces that need a textarea that automatically grows and shrinks to fit its content, authentication flows, and settings forms. Its implementation is provided as editable source so the final behavior and styling stay inside your project.
Technologies
No additional package dependency is declared for this component.
Installation
Usage
Max height
ref
current max height from ref: 0
Form
Customize
This is an example that you can use the hook useAutosizeTextArea() to create your own textarea to match your needs.
In this example, we use react-hook-form and shadcn-ui Textarea to fully control your customize textarea.
Props
| Prop | Type | Required | Description |
|---|---|---|---|
textAreaRef | HTMLTextAreaElement | null | Yes | Value accepted by the textAreaRef property in the exported source type. |
minHeight | number | No | Value accepted by the minHeight property in the exported source type. |
maxHeight | number | No | Value accepted by the maxHeight property in the exported source type. |
triggerAutoSize | string | Yes | Value accepted by the triggerAutoSize property in the exported source type. |
Use cases
- interfaces that need a textarea that automatically grows and shrinks to fit its content
- authentication flows
- settings forms
Features
- Copy-paste source that remains in your repository
- TypeScript source included with the component
- Tailwind CSS classes editable in the component source
- shadcn/ui dependencies: local UI primitives
- Spectrum UI registry dependencies: @spectrumui/autosize-textarea-dependecies
Accessibility
- Test focus order, keyboard operation, labels, contrast, and screen-reader output in the final application context.
Customization
- Edit the Tailwind utility classes in the copied source to match your spacing, color, and typography tokens.
- Use the documented className surface for local layout adjustments, then edit the source for structural changes.
Related components
Topic guides
See how this component fits into broader interface patterns, implementation decisions, and working examples.
Autosize Textarea FAQ
Is Autosize Textarea free to use in commercial projects?
Yes. The public Autosize Textarea source is available under the Apache License 2.0, including for commercial use, subject to the LICENSE terms.
How do I install Autosize Textarea?
Run npx shadcn@latest add @spectrumui/autosize-textarea-demo or npx shadcn@latest add @spectrumui/autosize-textarea-max-height or npx shadcn@latest add @spectrumui/autosize-textarea-ref or npx shadcn@latest add @spectrumui/autosize-textarea-form or npx shadcn@latest add @spectrumui/autosize-textarea-customize. The page also exposes the source for manual installation.
Does Autosize Textarea require Motion?
No Motion dependency was detected in the documented source or registry entry for Autosize Textarea.
Does Autosize Textarea use shadcn/ui or Radix UI?
Autosize Textarea uses local shadcn/ui primitives.
Can I use Autosize Textarea in Next.js?
The documented React source is used in this Next.js application. Keep its use client directive when copying it into the App Router. Install the detected dependencies and verify any application-specific data or image configuration.
What accessibility checks should I run for Autosize Textarea?
No component-specific accessibility mechanism was detected automatically. Test keyboard operation, focus, labels, contrast, and screen-reader output before shipping.