Skip to content
Slotted

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.

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.

bash
pnpm add @slotted/react @slotted/theme @slotted/themes
tsx
import { 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.

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.

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.

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.

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.

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.

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.

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.

59/150

Printed on a card inside the box.

98/120

Search results cut summaries after 120 characters.

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.

Error:

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.

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.

Maria Anders09:12
The customer called: the pallet has to arrive before the store opens at 8:00.
Thomas Hardy10:47
Booked with the early carrier. Tracking follows once the truck is loaded.

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'Default md
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'Default outline
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.
monobooleanDefault false
On Textarea, TextareaDefaultsProviderSets the value in the monospaced font with tabular figures, for a payload, a template or a diff.
resize'block' | 'none' | 'both'Default block
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.
autoSizebooleanDefault false
Grows the textarea with its content through CSS field-sizing, with no measurement in script. rows becomes the floor and maxRows the ceiling.
rowsnumberDefault 3
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.
maxRowsnumberDefault 12
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.
showCountbooleanDefault false
Publishes the length of the value to the field around it, which draws the count at the end of its label row.
countMaxnumberDefault maxLength
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

NamePayloadWhen
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, onBlurthe element’s own eventsWhenever 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

PartElementRequiredPurpose
roottextarea, or the element render returnsYesThe 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

TokenDefault
--slotted-textarea-backgroundvar(--slotted-control-surface, Field)
--slotted-textarea-border-colorvar(--slotted-control-border-color, ButtonBorder)
--slotted-textarea-colorvar(--slotted-text, CanvasText)
--slotted-textarea-disabled-backgroundvar(--slotted-disabled-background)
--slotted-textarea-disabled-border-colorvar(--slotted-disabled-border)
--slotted-textarea-disabled-colorvar(--slotted-disabled-foreground)
--slotted-textarea-hover-border-colorvar(--slotted-tone-accent-border)
--slotted-textarea-invalid-border-colorvar(--slotted-tone-danger-border)
--slotted-textarea-invalid-edge-widthvar(--slotted-control-invalid-edge-width, 1px)
--slotted-textarea-invalid-focus-ring-colorvar(--slotted-focus-ring-color-invalid, Highlight)
--slotted-textarea-line-heightvar(--slotted-line-height-md, 1.5)
--slotted-textarea-max-rows12
--slotted-textarea-placeholder-colorvar(--slotted-text-muted, GrayText)
--slotted-textarea-plain-hover-backgroundvar(--slotted-tone-secondary-subtle-hover)
--slotted-textarea-radiusvar(--slotted-control-radius, 4px)
--slotted-textarea-readonly-backgroundvar(--slotted-tone-secondary-subtle-hover)
--slotted-textarea-rows3
--slotted-textarea-shadowvar(--slotted-control-shadow, none)
--slotted-textarea-subtle-backgroundvar(--slotted-surface-sunken, Canvas)
--slotted-textarea-subtle-border-colorvar(--slotted-border-subtle, ButtonBorder)
--slotted-textarea-subtle-hover-backgroundvar(--slotted-tone-secondary-subtle-hover)

Theme tokens it reads

TokenDefault
--slotted-border-subtleSet per scheme by the theme
--slotted-control-border-colorSet per scheme by the theme
--slotted-control-border-widthvar(--slotted-border-width-thin)
--slotted-control-focus-ring-offsetvar(--slotted-focus-ring-offset)
--slotted-control-font-familyvar(--slotted-font-family-sans)
--slotted-control-font-size-lgcomfortable 14px · compact 13px · dense 12px
--slotted-control-font-size-mdcomfortable 13px · compact 12px · dense 12px
--slotted-control-font-size-smcomfortable 12px · compact 12px · dense 12px
--slotted-control-height-lgcomfortable 38px · compact 32px · dense 30px
--slotted-control-height-mdcomfortable 34px · compact 28px · dense 26px
--slotted-control-height-smcomfortable 30px · compact 26px · dense 24px
--slotted-control-invalid-edge-widthvar(--slotted-border-width-thin)
--slotted-control-padding-inline-lgcomfortable 16px · compact 12px · dense 10px
--slotted-control-padding-inline-mdcomfortable 13px · compact 10px · dense 8px
--slotted-control-padding-inline-smcomfortable 10px · compact 8px · dense 6px
--slotted-control-radiusvar(--slotted-radius-sm)
--slotted-control-shadowSet per scheme by the theme
--slotted-control-shadow-focus-geometry0 1px 4px -1px
--slotted-control-surfaceSet per scheme by the theme
--slotted-control-transition-durationvar(--slotted-duration-short)
--slotted-control-transition-easingvar(--slotted-easing-standard)
--slotted-disabled-backgroundSet per scheme by the theme
--slotted-disabled-borderSet per scheme by the theme
--slotted-disabled-foregroundSet per scheme by the theme
--slotted-focus-ring-colorSet per scheme by the theme
--slotted-focus-ring-color-invalidSet per scheme by the theme
--slotted-focus-ring-offsetvar(--slotted-border-width-thick)
--slotted-focus-ring-widthvar(--slotted-border-width-thick)
--slotted-font-family-mono'Geist Mono Variable', ui-monospace, SFMono-Regular, Menlo, monospace
--slotted-line-height-md1.5
--slotted-radius-none0px
--slotted-surface-sunkenSet per scheme by the theme
--slotted-textSet per scheme by the theme
--slotted-text-mutedSet per scheme by the theme
--slotted-tone-accent-borderSet per scheme by the theme
--slotted-tone-danger-borderSet per scheme by the theme
--slotted-tone-secondary-subtle-hoverSet per scheme by the theme