Skip to content

Auto-Resize Textarea for React

A glass React textarea that auto-resizes to fit its content and can show a character counter whose ring fills as you type.

npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/textarea.json
0 of 120 characters used

Auto-resize

Grows between minRows and maxRows, then scrolls. Measured off-screen, so the page never jumps while you type.

Grows from 2 up to 8 lines.

Files to copy

4 folders · 6 files · 4 packages
From theme/src/
  • components/textarea/
  • hooks/{use-controllable.ts, use-latest.ts}
  • lib/{cn.ts, field-size.ts, form.ts, warn-once.ts}
  • styles/
shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/textarea.jsonRegistry item: textarea. The styles need the Tailwind v4 glass UI setup.
The examples also use
  • components/button/
  • components/spinner/
  • components/toast/
  • hooks/{use-direction.ts, use-magnetic.ts, use-media-query.ts, use-preferences.ts}
  • motion/{gate.ts, tokens.ts}
  • lib/state-light.tsx
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/button.json https://lokendra-builds.github.io/sheenui/r/toast.json
Packages
pnpm add @base-ui/react clsx motion tailwind-merge

Character limit

The counter turns amber near the limit and red at it; typing past the limit is blocked with a little shake. Screen readers hear the count with the field and a polite note at 20 and 10 characters left.

78 of 140 characters used

Soft limit

limit="warn" lets people keep typing and trim later: the field turns invalid and the counter shows how far over it is. This bio is a few characters short of the limit; keep typing.

112 of 120 characters used

Shown on your public profile.

Props

PropTypeDefaultDescription
classNamestringNoneClass for the outer wrapper (label + field + messages).
maxLengthnumberNoneCharacter limit; shows the counter.
sizeFieldSize"md"Padding that matches Input at the same size: "sm" (one line is 32px tall), "md" (40px) or "lg" (48px); sm and md are 44px on touch screens.
labelReactNodeNoneText above the field, linked to the textarea as its accessible name.
descriptionReactNodeNoneMuted helper text under the field.
errorReactNodeNoneError message; marks the field invalid and is announced politely to screen readers when it appears.
autoResizebooleantrueGrow with the content between minRows and maxRows.
minRowsnumber3Height in lines when empty (and the fixed height when autoResize is off).
maxRowsnumber10Sets how tall it grows before scrolling, in lines.
limit"block" | "warn""block""block" (default) stops typing at maxLength; "warn" allows more but marks the field invalid.
showCountbooleanon when maxLength is setShow the counter. Without maxLength it counts up.
footerReactNodeNoneContent for the bottom row inside the field, left of the counter (e.g. buttons).
labelsPartial<TextareaLabels>defaultTextareaLabelsScreen-reader strings for the counter (i18n). Every other string, for translation: labels={{ count: "…" }}; omitted keys keep the English of defaultTextareaLabels. All 4 keys of TextareaLabels are listed in the key table under the props table.
textareaClassNamestringNoneAdds extra classes to the native <textarea>.
TextareaLabels keys and English defaults (4)
Pass any key in labels; the rest keep the defaults of defaultTextareaLabels.
KeyEnglish default
count(count, max) => (max === undefined ? characters(count) : `${count} of ${characters(max)} used`)
remaining(left) => `${characters(left)} left`
reachedCharacter limit reached
over(over) => `${characters(over)} over the limit`

Keyboard

KeysAction
Tab/Shift + TabMove focus to or from the textarea.
Type, select, undoEverything the native control does works.

Accessibility

  • label, description, error and the character count are linked with aria-labelledby and aria-describedby; an error is announced politely.
  • The character count sits in a polite live region. Text is 16 px on touch screens so iOS does not zoom.
  • autoResize grows the field with its content and keeps the caret and scroll position.

All exports on this page

  • Textarea — A glass multi-line field.
  • defaultTextareaLabels — Default English strings of TextareaLabels; spread it and override single keys to reword.

When to use Textarea

  • Use it as an auto-resize textarea for a comment box or a chat reply composer that should grow as people type, between minRows and maxRows, and then scroll instead of pushing the page down.
  • Use it for a profile bio with a 280 character limit, where the counter ring turns amber near the limit and red at it, and screen readers hear the count with the field.
  • Use it for a message form with actions beneath the text, since the footer prop places buttons in the bottom row left of the counter without extra layout code.
  • Skip it when the answer is a single line; Input handles that, and a code or rich text editor needs a dedicated editor component rather than a styled native textarea.
  • Pair it with Button in the footer slot for send or save, Rating above it for a feedback form, and the Field-style label, description and error props already built into it.

Frequently asked questions

67 components pages in all: browse them on All components.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .