oakoss/ui
Components

Textarea

A multiline text input that grows with its content, with a label, description and validation message.

SourceReact Aria
Shown on your profile.

Installation

npx shadcn@latest add @oakoss/textarea

TextareaField, which adds the label, description and error, comes with Text Field: install text-field for both.

Usage

import { TextareaField } from '#/components/ui/inputs/text-field';

<TextareaField description="Shown on your profile." label="Bio" />;

Examples

Rows

minRows (3 by default) sets the starting height and maxRows caps the growth, after which the box scrolls. Both are whole numbers of 1 or more, with maxRows at least minRows. One row is exactly an Input of the same size (sm, md, lg).

Starts at two rows and scrolls past five.

The box grows with CSS field-sizing: content, in Chrome and Edge 123, Safari 26.2 and Firefox 152 and later. Older browsers show minRows rows and keep the resize handle, so users can still drag the box taller.

Fixed height

autoGrow={false} keeps the box at minRows rows, scrolling past them, with a handle to resize it vertically:

Custom layout

children replace the default layout. Compose the Field parts around a Textarea, which wire up the label, description and error the same way:

What should we improve?

Children and the layout props (label, description, errorMessage, errors, placeholder, size, minRows, maxRows, autoGrow, start, end) can't be mixed; set those on the parts instead. start and end put text or an icon above and below the textarea, as on Text Field.

Accessibility

React Aria renders a native <textarea> and links it to its parts:

  • Name and description: the label names the textarea, and the description and error describe it (aria-labelledby, aria-describedby), with no ids to wire.
  • Validation: an invalid field sets aria-invalid, and isRequired sets the native required attribute. The required asterisk is hidden from screen readers, which already announce the field as required.

The border reaches 3:1 against the page at rest and when invalid, and the focus outline shows for any focus, mouse included. Where the box grows on its own, the resize handle is hidden, since dragging it would fix the height.

The textarea keeps the browser's own keyboard behavior, Enter included; React Aria adds no keys.

API

TextareaField

Extends React Aria's TextField with a Textarea in place of the input. With children, it renders only them.

Props

Prop

Type

Also accepts all React Aria TextField props.

Data attributes

AttributePresent when
data-slotAlways textarea-field
data-disabledisDisabled is set
data-invalidThe field is invalid
data-readonlyisReadOnly is set
data-requiredisRequired is set

Textarea

Extends React Aria's TextArea. minRows replaces the HTML rows attribute.

Props

Prop

Type

Also accepts all native <textarea> attributes except rows.

Data attributes

AttributePresent when
data-slotAlways textarea
data-sizeAlways: sm, md or lg
data-focusedThe textarea has focus
data-focus-visibleThe textarea has keyboard focus
data-hoveredThe pointer is over the textarea
data-disabledThe textarea is disabled
data-invalidThe field is invalid

CSS variables

VariableValue
--textarea-heightThe control height for size, one row tall
--textarea-min-rowsminRows
--textarea-max-rowsmaxRows, when set