Skip to the content
human-kit design
16 — Form

Textarea

A field for a few lines of text, growing with what is typed.

Installation

pnpm dlx @human-kit/design add textarea
npx @human-kit/design add textarea
yarn dlx @human-kit/design add textarea
bunx @human-kit/design add textarea

The command copies the files to src/lib/components/ui/textarea. It also installs the packages that the files import.

Usage

<script lang="ts">
	import * as Textarea from '$lib/components/ui/textarea';

	let notes = $state('');
</script>

<Textarea.Root aria-label="Notes" bind:value={notes} />

Examples

In a field

Inside a Field.Root, spread what the field hands over on the textarea. It gets its id, its label, the line under it and the error state, and turns red with the error.

Write why the appointment is cancelled.

Write why the appointment is cancelled.

Guidelines

  • Use a textarea for text that can run to more than one line: a note, a reason, a message. For a name or a number, use an Input.Root.
  • Use default in a form, and underline where the surface around it already is a box.
  • It starts at three lines and grows with what is typed up to twelve, then scrolls. Set minRows to how much you expect: one for a comment, more for a report.
  • Say in the label or the hint what to write, not in the placeholder alone: the placeholder goes away once the reader types.
  • Use readonly to show a text that cannot be changed: its box turns grey and loses its hover, and it still takes the focus to be selected and copied.

Accessibility

  • It renders a native <textarea>, so every key works as the browser has it, Enter included.
  • Name it with a Field.Root, a <label for>, or aria-label when there is no visible label.
  • invalid sets aria-invalid; with a Field.Root, the error is tied to it through aria-describedby.
  • disabled takes it out of the tab order. readonly keeps it in, and a screen reader says it cannot be edited.
  • The box grows instead of scrolling, so the end of the text is not hidden behind a scrollbar until it passes maxRows.

API reference

PropTypeDefault
variant'default' | 'filled' | 'ghost' | 'underline'

A white box, or one line under the text.

'default'
size'sm' | 'default' | 'lg'

The type, the corner and the inset, matching the fields of the same size.

'default'
valuestring

The text. Bindable.

—
autoResizeboolean

Grows the box with the text, between minRows and maxRows.

true
minRowsnumber

The height at rest, in lines.

3
maxRowsnumber

The tallest it grows, in lines. Past it the text scrolls.

12
invalidboolean

Marks the value as wrong: a red ring and aria-invalid.

false
readonlyboolean

Shows the text in a grey box. It can be focused and copied, not changed.

false
disabledboolean

Turns the field off and takes it out of the tab order.

false
elementHTMLTextAreaElement | null

The rendered element. Bindable.

—

Plus every attribute of a native <textarea>.