Textarea
Takes several lines of text on the native textarea element, with a height set in rows, growth with the content and a character count drawn by its field.
Printed on the packing slip for the carrier.
import { Field, FieldDescription, FieldLabel } from '@slotted/react/field';import { Textarea } from '@slotted/react/textarea';export default function TextareaBasic() { return ( <Field> <FieldLabel>Delivery instructions</FieldLabel> <Textarea placeholder="Gate code, loading dock, opening hours" /> <FieldDescription>Printed on the packing slip for the carrier.</FieldDescription> </Field> );}Installation
The packages are a 0.x beta on npm, and their public API changes between beta releases without deprecation. One line installs the binding and the default theme.
pnpm add @slotted/react @slotted/theme @slotted/themesimport { Textarea, TextareaDefaultsProvider } from '@slotted/react';Sizes
size sets the type, the padding and the row height to one step of the control scale: sm for dense tables and toolbars, md for most forms, lg for sparse forms. A textarea of one row is as tall as a text field of the same step. Inside a field, the textarea takes the field’s size when it states none of its own.
import { Field, FieldLabel } from '@slotted/react/field';import { Stack } from '@slotted/react/stack';import { Textarea } from '@slotted/react/textarea';export default function TextareaSizes() { return ( <Stack gap={5}> <Field size="sm"> <FieldLabel>Line item note</FieldLabel> <Textarea rows={2} defaultValue="Pack the glass bottles separately." /> </Field> <Field size="md"> <FieldLabel>Order note</FieldLabel> <Textarea rows={2} defaultValue="The customer asked for delivery before noon on Friday." /> </Field> <Field size="lg"> <FieldLabel>Message to the supplier</FieldLabel> <Textarea rows={2} defaultValue="Please confirm the revised quantities by Wednesday." /> </Field> </Stack> );}Variants
variant sets how much frame the textarea draws, with the same three frames as the text field. outline draws a border on the surface it sits on, subtle sinks into a tinted ground, and plain draws no border or background until hover, for a textarea inside a table cell or a card that already frames it.
import { Field, FieldLabel } from '@slotted/react/field';import { Stack } from '@slotted/react/stack';import { Textarea } from '@slotted/react/textarea';export default function TextareaVariants() { return ( <Stack gap={5}> <Field> <FieldLabel>Return reason</FieldLabel> <Textarea variant="outline" rows={2} defaultValue="Two jars arrived with broken seals." /> </Field> <Field> <FieldLabel>Warehouse note</FieldLabel> <Textarea variant="subtle" rows={2} defaultValue="Restock on shelf B4 after inspection." /> </Field> <Field> <FieldLabel>Picker comment</FieldLabel> <Textarea variant="plain" rows={2} defaultValue="Counted twice, 46 units on hand." /> </Field> </Stack> );}Monospaced text
mono sets the value in the monospaced font with tabular figures. Use it for a JSON payload, a template or a code snippet, where characters must line up between lines. Turn spellCheck off for content that is not prose.
Sent to your endpoint when you press Send test event.
import { Field, FieldDescription, FieldLabel } from '@slotted/react/field';import { Textarea } from '@slotted/react/textarea';const PAYLOAD = `{ "event": "order.shipped", "orderId": 10248, "carrier": "Federal Shipping", "tracking": "FS-2026-0042-7731"}`;export default function TextareaMono() { return ( <Field> <FieldLabel>Test payload</FieldLabel> <Textarea mono variant="subtle" rows={7} spellCheck={false} defaultValue={PAYLOAD} /> <FieldDescription>Sent to your endpoint when you press Send test event.</FieldDescription> </Field> );}States
invalid sets aria-invalid and draws the border in the danger tone, with a wider edge. readOnly sets the native readonly: the text stays focusable, selectable and submitted, and the resize handle stays. disabled sets the native disabled, which takes the textarea out of the tab order and out of form submission and removes the handle. Set the state on the field, and the textarea inside it follows.
Error:Describe the damage in at least 20 characters.
Written by the customer at checkout.
Locked once the shipment is booked.
import { Field, FieldDescription, FieldError, FieldLabel } from '@slotted/react/field';import { Stack } from '@slotted/react/stack';import { Textarea } from '@slotted/react/textarea';export default function TextareaStates() { return ( <Stack gap={5}> <Field invalid required> <FieldLabel>Damage report</FieldLabel> <Textarea rows={2} defaultValue="Box dented." /> <FieldError>Describe the damage in at least 20 characters.</FieldError> </Field> <Field readOnly> <FieldLabel>Customer note</FieldLabel> <Textarea rows={2} defaultValue="Please ring the bell twice. The office is on the second floor." /> <FieldDescription>Written by the customer at checkout.</FieldDescription> </Field> <Field disabled> <FieldLabel>Carrier instructions</FieldLabel> <Textarea rows={2} defaultValue="Leave with the building manager." /> <FieldDescription>Locked once the shipment is booked.</FieldDescription> </Field> </Stack> );}Read-only long text
A read-only textarea holds a long text a reader has to scroll, select and copy, such as agreed terms or a log entry, at the height rows sets. The text keeps its full contrast, and the resize handle lets the reader open it to its full length.
Agreed with Exotic Liquids on 3 March 2026.
import { Field, FieldDescription, FieldLabel } from '@slotted/react/field';import { Textarea } from '@slotted/react/textarea';const TERMS = `1. Payment. Invoices are payable within 30 days of the invoice date. Late payments carry interest of 1% per month.2. Delivery. The supplier ships within five business days of a confirmed purchase order. Partial shipments are invoiced separately.3. Returns. Goods damaged in transit are reported within 48 hours of receipt, with photographs of the packaging.4. Prices. Prices are fixed for the term of this agreement and reviewed every January.5. Termination. Either party may end this agreement with 60 days' written notice.`;export default function TextareaReadOnly() { return ( <Field> <FieldLabel>Supplier terms</FieldLabel> <Textarea readOnly rows={6} defaultValue={TERMS} /> <FieldDescription>Agreed with Exotic Liquids on 3 March 2026.</FieldDescription> </Field> );}Rows and the resize handle
rows sets the height in lines; the default is 3. resize decides which way the handle in the corner drags: block, the default, changes only the height, so the textarea never grows wider than its field. none removes the handle, and both adds the width.
import { Field, FieldLabel } from '@slotted/react/field';import { Stack } from '@slotted/react/stack';import { Textarea } from '@slotted/react/textarea';export default function TextareaRows() { return ( <Stack gap={5}> <Field> <FieldLabel>Gift message</FieldLabel> <Textarea rows={2} resize="none" defaultValue="Happy birthday, Laura. Enjoy the tea." /> </Field> <Field> <FieldLabel>Incident report</FieldLabel> <Textarea rows={5} placeholder="What happened, when, and who was involved" /> </Field> <Field> <FieldLabel>Reply draft</FieldLabel> <Textarea resize="both" placeholder="Drag the corner to resize in both directions" /> </Field> </Stack> );}Growing with the content
autoSize makes the textarea grow as lines are added, from rows lines up to maxRows lines, the default 12. Past the ceiling it scrolls, so the page under the caret stays where it is. The resize handle is removed while autoSize is on. The growth uses CSS field-sizing; a browser without it keeps the height of rows. Add lines to the note until it stops growing.
Shown to the picker on the warehouse screen.
import { Field, FieldDescription, FieldLabel } from '@slotted/react/field';import { Textarea } from '@slotted/react/textarea';export default function TextareaAutoSize() { return ( <Field> <FieldLabel>Picking note</FieldLabel> <Textarea autoSize rows={2} maxRows={6} defaultValue="Use the reinforced boxes for the olive oil." /> <FieldDescription>Shown to the picker on the warehouse screen.</FieldDescription> </Field> );}Character count
showCount publishes the length of the value, and the field draws the count at the end of its label row. With maxLength, the count shows the native limit, which refuses input past it. countMax without maxLength is a soft limit: the value may pass it, and the count turns to the danger tone when it does. Type past 120 characters in the summary.
Printed on a card inside the box.
Search results cut summaries after 120 characters.
import { Field, FieldDescription, FieldLabel } from '@slotted/react/field';import { Stack } from '@slotted/react/stack';import { Textarea } from '@slotted/react/textarea';export default function TextareaCount() { return ( <Stack gap={5}> <Field> <FieldLabel>Gift message</FieldLabel> <Textarea rows={2} maxLength={150} showCount defaultValue="Happy anniversary to the whole team at Alfreds Futterkiste." /> <FieldDescription>Printed on a card inside the box.</FieldDescription> </Field> <Field> <FieldLabel>Product summary</FieldLabel> <Textarea rows={3} countMax={120} showCount defaultValue="Hand-picked Darjeeling first flush, packed in resealable tins of 100 grams. Ships within two days." /> <FieldDescription>Search results cut summaries after 120 characters.</FieldDescription> </Field> </Stack> );}Validation in a form
Enter adds a line and never submits the form, so a form with a textarea submits through its button. Validate on submit, then set invalid on the field and write the error; the field marks the textarea with aria-invalid and adds the error to its accessible description. The Angular example binds the textarea to a reactive form control with Validators.required and Validators.minLength. Submit the empty form, then write a description and submit again.
import { useState, type SubmitEvent } from 'react';import { Button } from '@slotted/react/button';import { Field, FieldError, FieldLabel } from '@slotted/react/field';import { Inline } from '@slotted/react/inline';import { Stack } from '@slotted/react/stack';import { Textarea } from '@slotted/react/textarea';const MIN_LENGTH = 20;function detailsError(value: string): string { if (value === '') return 'Describe what is wrong with the item.'; if (value.length < MIN_LENGTH) return `Add more detail: at least ${MIN_LENGTH} characters.`; return '';}export default function TextareaValidation() { const [details, setDetails] = useState(''); const [submitted, setSubmitted] = useState(false); const [sent, setSent] = useState(false); const error = submitted ? detailsError(details) : ''; const submit = (event: SubmitEvent<HTMLFormElement>) => { event.preventDefault(); setSubmitted(true); setSent(detailsError(details) === ''); }; return ( <form noValidate onSubmit={submit}> <Stack gap={4}> <Field required invalid={error !== '' ? true : undefined}> <FieldLabel>What is wrong with the item?</FieldLabel> <Textarea value={details} onValueChange={(value) => { setDetails(value); setSent(false); }} /> <FieldError live="polite" reserve> {error} </FieldError> </Field> <Inline gap={3} align="center"> <Button type="submit">Request a return</Button> {sent ? <span role="status">Return requested.</span> : null} </Inline> </Stack> </form> );}Defaults for a section
TextareaDefaultsProvider in React and provideTextareaDefaults in Angular set size, variant, mono and resize once for every textarea under them. A textarea that states a value of its own keeps it, and a textarea inside a field takes the field’s size over the provider’s.
import { Field, FieldLabel } from '@slotted/react/field';import { Stack } from '@slotted/react/stack';import { Textarea, TextareaDefaultsProvider } from '@slotted/react/textarea';export default function TextareaDefaults() { return ( <TextareaDefaultsProvider variant="subtle" resize="none"> <Stack gap={5}> <Field> <FieldLabel>Reply to the customer</FieldLabel> <Textarea rows={2} defaultValue="Your refund was issued today." /> </Field> <Field> <FieldLabel>Internal note</FieldLabel> <Textarea rows={2} defaultValue="Refund approved by finance." /> </Field> <Field> <FieldLabel>Escalation summary</FieldLabel> <Textarea variant="outline" rows={2} defaultValue="Second refund request this quarter." /> </Field> </Stack> </TextareaDefaultsProvider> );}Comment composer
A comment thread with a composer under it. The textarea is controlled: value and onValueChange in React, [value] and (valueChange) in Angular, so the page clears it after the comment is posted. It starts at two rows and grows to eight. Write a comment over two or three lines and press Post comment.
import { useState, type SubmitEvent } from 'react';import { Button } from '@slotted/react/button';import { Field, FieldLabel } from '@slotted/react/field';import { Inline } from '@slotted/react/inline';import { Stack } from '@slotted/react/stack';import { Textarea } from '@slotted/react/textarea';import { Text } from '@slotted/react/typography';interface Comment { id: number; author: string; time: string; body: string;}const THREAD: Comment[] = [ { id: 1, author: 'Maria Anders', time: '09:12', body: 'The customer called: the pallet has to arrive before the store opens at 8:00.', }, { id: 2, author: 'Thomas Hardy', time: '10:47', body: 'Booked with the early carrier. Tracking follows once the truck is loaded.', },];export default function TextareaCommentComposer() { const [comments, setComments] = useState(THREAD); const [draft, setDraft] = useState(''); const submit = (event: SubmitEvent<HTMLFormElement>) => { event.preventDefault(); const body = draft.trim(); if (body === '') return; setComments((current) => [ ...current, { id: current.length + 1, author: 'You', time: 'Just now', body }, ]); setDraft(''); }; return ( <Stack gap={6}> <Stack gap={4}> {comments.map((comment) => ( <Stack key={comment.id} gap={1}> <Inline gap={2} align="baseline"> <Text size="sm" weight="semibold"> {comment.author} </Text> <Text size="sm" tone="muted"> {comment.time} </Text> </Inline> <Text size="sm">{comment.body}</Text> </Stack> ))} </Stack> <form onSubmit={submit}> <Stack gap={3}> <Field> <FieldLabel>Comment on order 10248</FieldLabel> <Textarea autoSize rows={2} maxRows={8} placeholder="Write an update for the team" value={draft} onValueChange={setDraft} /> </Field> <Inline justify="end"> <Button type="submit">Post comment</Button> </Inline> </Stack> </form> </Stack> );}Accessibility
- The WAI-ARIA Authoring Practices define no pattern for a multi-line text control. Textarea follows the HTML specification for the element and the ARIA textbox role, whose aria-multiline the native element supplies.
- Inside a field, the textarea takes its accessible name from the field’s label, whose for attribute points at the identifier the field generates. aria-describedby lists any value you write first, then the ones the field adds: help, description, count and error.
- A required field sets aria-required, not the native required. The native attribute turns on browser constraint validation and changes how the form submits; write required on the textarea to opt in, and it is kept. disabled and readonly are the native attributes.
- Enter adds a line and never submits the form. WAI-ARIA describes this as the difference between a single-line and a multi-line text control, and a comment box that submitted on Enter would lose what was being written.
- Tab moves focus out of the textarea. No key is bound, so no shortcut holds keyboard focus inside it.
- Growth with the content is CSS, not script: the textarea takes its new height with no animation, so a screen reader announces nothing and a reader who asked for reduced motion sees no movement.
API
Textarea
Props
valuestring- Makes the value controlled for the life of the component. Without it the element keeps its own value, and a native form reset restores defaultValue.
defaultValuestring- The value an uncontrolled textarea starts from. It is read once and written to the element, which is what a form reset returns to.
size'sm' | 'md' | 'lg'Defaultmd- On Textarea, TextareaDefaultsProviderThe step of the control scale. When unset, the textarea takes the size of its field, then of the provider. The vertical padding is derived from the step, so a textarea of one row is as tall as a text field of the same step at every density.
variant'outline' | 'subtle' | 'plain'Defaultoutline- On Textarea, TextareaDefaultsProviderHow much frame the textarea draws: the three frames of the text field, read from the same tokens. When unset, the textarea takes the variant of the provider.
monobooleanDefaultfalse- On Textarea, TextareaDefaultsProviderSets the value in the monospaced font with tabular figures, for a payload, a template or a diff.
resize'block' | 'none' | 'both'Defaultblock- On Textarea, TextareaDefaultsProviderWhich way the resize handle drags. The default is block rather than the platform’s both, because a textarea wider than its field breaks the field’s grid. While autoSize is on, the handle is removed.
autoSizebooleanDefaultfalse- Grows the textarea with its content through CSS field-sizing, with no measurement in script. rows becomes the floor and maxRows the ceiling.
rowsnumberDefault3- The starting height in lines, and the floor while autoSize is on. The default is 3 rather than the platform’s 2, because a box of two rows reads as a mistyped input.
maxRowsnumberDefault12- The ceiling autoSize grows to, in lines; past it the textarea scrolls. It cannot be removed, because a textarea that grows without limit pushes the page out from under the caret.
showCountbooleanDefaultfalse- Publishes the length of the value to the field around it, which draws the count at the end of its label row.
countMaxnumberDefaultmaxLength- The limit the count is measured against; it defaults to maxLength. Without maxLength it is a soft limit: the value may pass it, and the count is then drawn as invalid.
disabledbooleanDefault from the field, or false- Unset rather than false, so the textarea follows the field around it. When set, it wins over the field and writes the native disabled.
readOnlybooleanDefault from the field, or false- Unset rather than false, so the textarea follows the field around it. Writes the native readonly: the textarea stays focusable, selectable and submitted, and keeps its resize handle.
invalidbooleanDefault from the field, or false- Unset rather than false, so the textarea follows the field around it. Writes aria-invalid and data-invalid.
requiredboolean- The element’s own attribute, passed through unchanged; Textarea never writes it. Inside a required field, the textarea receives aria-required instead.
Events
| Name | Payload | When |
|---|---|---|
onValueChange | (value: string, request: ChangeRequest<string>) | Before the value moves. request.value is the new value and request.previous the value it replaces. request.reason is always keyboard, because only an edit in the textarea moves the value, and request.source is the originating event. request.cancel() refuses the change: the count does not move, and an uncontrolled element keeps what was typed. |
onChange, onInput, onFocus, onBlur | the element’s own events | Whenever the textarea fires them. Textarea composes your handler with its own instead of replacing it: yours runs first, and always runs. |
Composition
render(props: TextareaRootProps) => ReactNode- Renders another element in place of the textarea and passes it every attribute, including the two custom properties that carry rows and maxRows. The props are typed as HTMLAttributes<HTMLElement>, so they spread onto any element.
refRef<HTMLTextAreaElement>- Reaches the textarea element. focus(), select() and setSelectionRange() are the element’s own, so Textarea adds no imperative handle.
TextareaDefaultsProvider{ size, variant, mono, resize }- On a subtreeSets size, variant, mono and resize once for every textarea under it. A textarea that states a value keeps it, and a textarea inside a field takes the field’s size over the provider’s.
useField()() => FieldContextValue | undefined- On inside a FieldWhat Textarea reads inside a Field to wire itself: the identifier, the description, the disabled, read-only, invalid and required states, and the channel it publishes its count on.
Parts
| Part | Element | Required | Purpose |
|---|---|---|---|
root | textarea, or the element render returns | Yes | The textarea element, which is both the control and its frame. It carries data-ui="textarea", data-size, data-variant and data-resize, data-mono and data-auto-size when they are on, and data-disabled, data-invalid and data-readonly. It has no wrapper: the text field wraps its input so that buttons can sit inside one border, but no adornment sits inside a textarea, and its corner holds the resize handle. |
Theming
Each token is a CSS custom property: set it in a theme, or on any element to retune every textarea inside it.
Textarea tokens
| Token | Default |
|---|---|
--slotted-textarea-background | var(--slotted-control-surface, Field) |
--slotted-textarea-border-color | var(--slotted-control-border-color, ButtonBorder) |
--slotted-textarea-color | var(--slotted-text, CanvasText) |
--slotted-textarea-disabled-background | var(--slotted-disabled-background) |
--slotted-textarea-disabled-border-color | var(--slotted-disabled-border) |
--slotted-textarea-disabled-color | var(--slotted-disabled-foreground) |
--slotted-textarea-hover-border-color | var(--slotted-tone-accent-border) |
--slotted-textarea-invalid-border-color | var(--slotted-tone-danger-border) |
--slotted-textarea-invalid-edge-width | var(--slotted-control-invalid-edge-width, 1px) |
--slotted-textarea-invalid-focus-ring-color | var(--slotted-focus-ring-color-invalid, Highlight) |
--slotted-textarea-line-height | var(--slotted-line-height-md, 1.5) |
--slotted-textarea-max-rows | 12 |
--slotted-textarea-placeholder-color | var(--slotted-text-muted, GrayText) |
--slotted-textarea-plain-hover-background | var(--slotted-tone-secondary-subtle-hover) |
--slotted-textarea-radius | var(--slotted-control-radius, 4px) |
--slotted-textarea-readonly-background | var(--slotted-tone-secondary-subtle-hover) |
--slotted-textarea-rows | 3 |
--slotted-textarea-shadow | var(--slotted-control-shadow, none) |
--slotted-textarea-subtle-background | var(--slotted-surface-sunken, Canvas) |
--slotted-textarea-subtle-border-color | var(--slotted-border-subtle, ButtonBorder) |
--slotted-textarea-subtle-hover-background | var(--slotted-tone-secondary-subtle-hover) |
Theme tokens it reads
| Token | Default |
|---|---|
--slotted-border-subtle | Set per scheme by the theme |
--slotted-control-border-color | Set per scheme by the theme |
--slotted-control-border-width | var(--slotted-border-width-thin) |
--slotted-control-focus-ring-offset | var(--slotted-focus-ring-offset) |
--slotted-control-font-family | var(--slotted-font-family-sans) |
--slotted-control-font-size-lg | comfortable 14px · compact 13px · dense 12px |
--slotted-control-font-size-md | comfortable 13px · compact 12px · dense 12px |
--slotted-control-font-size-sm | comfortable 12px · compact 12px · dense 12px |
--slotted-control-height-lg | comfortable 38px · compact 32px · dense 30px |
--slotted-control-height-md | comfortable 34px · compact 28px · dense 26px |
--slotted-control-height-sm | comfortable 30px · compact 26px · dense 24px |
--slotted-control-invalid-edge-width | var(--slotted-border-width-thin) |
--slotted-control-padding-inline-lg | comfortable 16px · compact 12px · dense 10px |
--slotted-control-padding-inline-md | comfortable 13px · compact 10px · dense 8px |
--slotted-control-padding-inline-sm | comfortable 10px · compact 8px · dense 6px |
--slotted-control-radius | var(--slotted-radius-sm) |
--slotted-control-shadow | Set per scheme by the theme |
--slotted-control-shadow-focus-geometry | 0 1px 4px -1px |
--slotted-control-surface | Set per scheme by the theme |
--slotted-control-transition-duration | var(--slotted-duration-short) |
--slotted-control-transition-easing | var(--slotted-easing-standard) |
--slotted-disabled-background | Set per scheme by the theme |
--slotted-disabled-border | Set per scheme by the theme |
--slotted-disabled-foreground | Set per scheme by the theme |
--slotted-focus-ring-color | Set per scheme by the theme |
--slotted-focus-ring-color-invalid | Set per scheme by the theme |
--slotted-focus-ring-offset | var(--slotted-border-width-thick) |
--slotted-focus-ring-width | var(--slotted-border-width-thick) |
--slotted-font-family-mono | 'Geist Mono Variable', ui-monospace, SFMono-Regular, Menlo, monospace |
--slotted-line-height-md | 1.5 |
--slotted-radius-none | 0px |
--slotted-surface-sunken | Set per scheme by the theme |
--slotted-text | Set per scheme by the theme |
--slotted-text-muted | Set per scheme by the theme |
--slotted-tone-accent-border | Set per scheme by the theme |
--slotted-tone-danger-border | Set per scheme by the theme |
--slotted-tone-secondary-subtle-hover | Set per scheme by the theme |