Multi-line text that grows one line at a time on a spring, with a floating label thrown onto the rim, a ball resize grip, a limit-ring counter, validation states and composer and note presets.
TypeType
Ticket #4821
Refund for duplicate charge
Open
Requester
I was charged twice for the March invoice. Could you refund the second payment?
0/1000Ctrl↵
0 of 1000 characters
Sent from support@example.comNo draft yet
textarea · , lively
textarea-demo.tsx
When to use
Use for multi-line text of varying length. It grows one line at a time up to maxRows, with a character counter ring. Presets: floating, composer (Mod+Enter submit), note.
Use it for multi-line text that varies in length: notes, descriptions, feedback, a message in a
thread. The field reserves minRows, grows one whole line at a time on a spring (also on paste, in
a single spring) and stops at maxRows, where it scrolls. For a single line, use text-field;
for a fixed-height editor with formatting, use a rich-text editor.
Focus shares the text field's moment: the 2px ring rim lights at once, and the floating label's
pill stretches up under your press, is thrown onto the top edge on release (at once on keyboard
focus) and lands there with a small squash, tinted toward ring. The native placeholder appears
only once the pill has left the first line. The composer and note presets have no floating label:
their focus is the lit rim alone, the quiet that dense contexts want.
Growth follows the three beats too. Typing a new line is the action: the height springs to the measured size and everything below
reflows with it. At maxRows the arriving line settles by pressing the field's box against its
bottom edge, never the text; the scroll only ever moves forward, so the text never jumps back a
line. The grip in the corner is a ball you drag and release onto the nearest line, and the counter
rolls its digits.
The counter carries a small limit ring that fills with the text. From 90% of maxLength the ring
turns warning, the digits step up to foreground and a polite announcement says how many
characters are left; past the limit the ring is full and destructive and the count keeps counting
("300/280"). States match the text field: error raises a destructive rim from the bottom edge,
valid sweeps a success rim in from the left and traces the check of its message, and
required adds the 4px primary dot after the label.
Three presets change layout and configuration, not the look. floating (default) has a label
that lifts, the grip and the counter. composer hides the label (give it aria-label), has an
action row with a send button, submits on Mod + Enter through onSubmit and grows without a
grip. Next to Send it shows the platform's Mod + Enter hint (⌘ ↵ or Ctrl ↵) when
onSubmit is set and the field is wide enough; turn it off with submitHint={false}. On a narrow
field its send button goes icon-only (the label stays its accessible name) and the
counter steps aside, so the button always keeps its inset inside the rim. note is an inline field
for detail panes and table cells: no rim until hover, the lit rim on focus, one row to start, calm
reflow.
import { Textarea, TextareaAction } from "@/components/ui/textarea"<Textarea preset="composer" aria-label="Reply" placeholder="Write a reply" value={reply} onValueChange={setReply} loading={sending} onSubmit={send} submitLabel="Send" actions={ <TextareaAction aria-label="Attach a file"> <PaperclipIcon /> </TextareaAction> }/><Textarea preset="note" aria-label="Internal note" />
Set the character per field with temperament (calm | lively | playful) or for the whole app
with MotionKitProvider. size is sm, md or lg; growth always lands on whole lines of the
size's line height. dense forces the calm reflow for table cells and forms that show errors.
The draft lands as a paste would, in one spring. Bold wraps the selection in Markdown, Attach adds
a file chip, and the canned replies append a line so the field grows to take it. A pause in typing
saves the draft ("Draft saved 3 s ago"). Sending turns the button into a spinner and the text
read-only, then the reply joins the thread with its files and the field shrinks back to minRows.
TypeType
Ticket #4821
Refund for duplicate charge
Open
Requester
I was charged twice for the March invoice. Could you refund the second payment?
It is a native <textarea>, so selection, spellcheck, autofill and form submission work as
usual. All native props pass through (name, required, readOnly, placeholder, aria-*).
Give it a name: the visible label, or aria-label (required in composer, where the label
is visually hidden but still read). description and error are linked with
aria-describedby; error sets aria-invalid, a valid message is linked the same way, and
required sets required and aria-required (the dot itself is aria-hidden).
Messages sit in a polite live region. The counter has a screen reader status that announces the
count politely once on entering 90% of the limit, at the limit and past it, never per keystroke;
the rolling digits and the limit ring are aria-hidden. The warning is never carried by amber
text (it would fail AA): the digits turn foreground and only the ring is warning.
The valid message's words stay foreground; the success check beside them carries the colour.
The composer's Mod + Enter hint is aria-hidden; the send button exposes the shortcut through
aria-keyshortcuts.
The grip is a role="separator" with aria-orientation, aria-label="Resize",
aria-controls pointing at the textarea and aria-valuemin, aria-valuemax and
aria-valuenow in rows. It is focusable and shows a 3px ring on keyboard focus.
The surface, the pill's decorative layers, the mirror and the ball are decorative
(aria-hidden); the label is a real <label htmlFor> and its text stays foreground (never
ring), so the 14% ring tint never carries text contrast.
Focus is always visible: the lit 2px rim is there the instant focus arrives, plus a 3px ring/50
halo for keyboard focus (destructive/20 on an invalid field).
Helper text and error share one slot: the error rises into it and leaves first, then the helper
returns in the same place, so nothing below the field moves.
Past maxLength the text is not cut: the counter keeps counting ("300/280") in destructive, the
live region announces how many characters are over and the error explains it, so state is not
conveyed by color alone. Each digit leaves its slot before the next one rolls in.
On touch devices the grip's hit area grows to 44px. Colors come from your shadcn tokens
(background, input, muted-foreground, destructive, ring), so contrast follows your theme
in light and dark. Disabled fields use muted and keep readable text.
With reduced motion (the OS setting, or MotionKitProvider reducedMotion="always") height changes
glide in the 120ms fade instead of the spring, the label pill glides to the rim in the same fade
with no stretch or squash while its tint and the lit rim fade in, the grip does not stretch, the ceiling does not squash, counter digits
crossfade, the limit ring moves in the same short fade, the success rim fades in whole instead of
sweeping and the check is drawn whole. Nothing disappears: every state and every message is still shown.
The field's height is the only layout-affecting value that moves, and it moves on one spring per
change, so siblings reflow once, not per keystroke. The ball, the ceiling squash and the label
pill animate transform and opacity; the lit rim is one box-shadow transition, with no SVG
and no path to recompute.
A hidden mirror measures the text; a ResizeObserver re-measures when the width changes. There
is no per-frame JavaScript while the field is idle.
The composer's sending spinner pauses off screen and in hidden tabs (useShouldAnimate).
The only dependency is motion; nothing is loaded lazily.
Technical sheet
Motion
calm
260 ms · bounce 0
lively
400 ms · bounce 0.3
playful
540 ms · bounce 0.45
Main spring of each temperament. Set it with the temperament prop or MotionKitProvider; the default is lively.
Size
Not measured yet · budget 15.0 kB gzip
Component and MotionKit helpers; excludes react, react-dom, motion.
Dependencies
motion · peer
Triggers
typing, drag, keyboard focus, press
Reduced motion
Height changes, the label pill, the counter and its limit ring move in the 120ms fade with no stretch or squash; the success rim fades in whole instead of sweeping and the check is drawn whole.
Keyboard
Tab / Shift + Tab
Into the textarea, then to the resize grip (when resizable), then out
Enter
Inserts a new line; the field grows one row on a spring
Mod + Enter
Calls onSubmit (composer send); the composer shows the hint next to Send
ArrowUp / ArrowDown
On the grip: one row smaller or larger
PageUp / PageDown
On the grip: three rows smaller or larger
Home / End
On the grip: minRows or maxRows
Browsers
Last 2 versions of Chrome, Edge, Firefox and Safari (iOS 16.4+)