Skip to content
Sveltier
Mode
Forms

Textarea

Several lines of text, in the same field as a TextField: label, hint, validation, and the option to grow with its text.

Usage

Bind the value and give it a label. rows sets how many lines show. The user can drag it taller; with autoGrow it grows with its text instead, from rows up to maxRows, and then scrolls.

Grows from 2 to 8 lines, then scrolls

At least 20 characters, so we can help

0 / 280 characters in the note.

PaymentNote.svelte
<script>
  import { Textarea } from 'sveltier';
  let note = $state('');
</script>

<!-- Grows with its text from 2 to 8 lines, then scrolls. -->
<Textarea
  label="Note to the payee"
  name="note"
  hint="They see it on their statement"
  maxlength={280}
  rows={2}
  autoGrow
  maxRows={8}
  bind:value={note}
/>

Validation

required, minlength, maxlength, rules, error and validateOn work as they do on a TextField, and inside a Form.

Next to other fields

The first line sits where a TextField puts its text, so a one-row Textarea is exactly as tall as a TextField of the same size and density, and the two line up in a row. Lines are spaced for reading.

Accessibility

  • The label, the hint and the error are linked to the <textarea> as on every field.
  • Growing uses field-sizing: content where the browser has it, and measures the text where it does not, so no line is ever hidden under the edge.

API

NameTypeDefaultDescription
variant'outlined' | 'tonal' | 'elevated' | 'text' | 'plain''outlined'How the box is drawn.
colorColor'primary'The accent of the focused field. An invalid field uses error.
size'xs' | 'sm' | 'md' | 'lg' | 'xl''md'Height and text size, matching a Button of the same size.
density'compact' | 'default' | 'comfortable''default'Multiplies the height and padding, never the text.
roundedboolean | 'none' | 'sm' | 'md' | 'lg' | 'xl' | 'full'trueCorner rounding. true keeps the theme's radius.
disabledbooleanfalseMutes the field and disables its control.
labelstring–The visible label, linked to the control. Without it, name the control with aria-label.
hintstring–Help under the field. An error replaces it.
errorFieldError–An error from outside the field, such as the server's answer: a message, a list of which the first is shown, or true for an invalid state described elsewhere.
prependSnippet–Content at the start of the box, usually an icon.
appendSnippet–Content at the end of the box: an icon, a unit or a button.
valuestring–The text. Bindable.
rowsnumber3Visible lines, and the fewest it shows when it grows.
autoGrowbooleanfalseGrows with its text instead of scrolling, up to maxRows.
maxRowsnumber–With autoGrow, the most lines it grows to before it scrolls. Unlimited when not set.
rulesreadonly Rule<string>[]–Checks run in order after the HTML constraints. The first message is shown.
validateOn'blur' | 'input' | 'submit'–When the message shows. Defaults to the form's setting, else 'blur'.
requiredbooleanfalseThe field must not be empty. Adds an asterisk to the label.
readonlybooleanfalseThe text can be read, selected and copied but not changed.
stylestring | null–Inline style of the field's root element.
classClassValue | null–Classes added after the component's own: a string, an array or an object.
refHTMLTextAreaElement | null–The root element, bindable with bind:ref.