Skip to content
EspañolEnglish
All components (283)

Long text

Fields · TextArea

What it is and when to use it

The long text field: notes, delivery instructions, reasons. It starts with the rows you ask for, grows as you type up to 20 lines (after that the scrollbar appears) and can be stretched by hand downward, never sideways.

When to use it

  • Anything that can take up more than one line: the remarks on an order, the reason for a return, the description of a product.
  • rows for the starting height (1 to 12). counter with maxLength when there is a limit to respect, like the summary that appears in an email.

When not to

  • A single line (a name, a reference): TextField.
  • Replying in a comment thread: Comments, which already includes its reply field.

Keyboard: Tab enters and leaves; Enter inserts a line break, it does not submit the form.

Accessibility: the label is required; the hint and the error are read as the description. With counter, the count ("123 / 500") is always visible but is only announced when 20 characters or fewer are left ("15 characters left") and on reaching the limit: a count on every keystroke would run over the screen reader. When few are left, the count switches to the warning color and to bold, it does not only change color.

Fine-tuning: no variables of its own: it uses those of the field (--amset-field-*) and is adjusted with the classes amset-area__control, amset-area__entry, amset-area__footer and amset-area__counter. Growing on its own depends only on field-sizing: where the browser does not support it, it stays at its rows and is stretched by hand.

What it looks like

<TextArea label="Delivery instructions" placeholder="Front desk, opening hours..." rows={3} />
<TextArea label="Email summary" counter maxLength={160} hint="Shown in the email the customer receives" />

Props

Import it with import { TextArea } from '@amset/ui'. Required props are marked.

PropTypeWhat it does
labelrequiredstring—
classNamestring—
countByCountStrategyHow characters are counted: `graphemes` (default, an emoji with its skin tone is one), `characters` (what `maxLength` measures) or a custom function (words, bytes).
counterboolean | "inside"Shows "123 / 500", with the limit of `maxCount` or `maxLength`. `inside` puts it inside the border, bottom right, instead of under the field.
defaultValuestring—
disabledboolean—
errorstring—
footerReactNodeA strip inside the border, under the text: formatting buttons, an attachment. The `inside` counter goes next to it.
hiddenLabelbooleanThe label for the screen reader only. For when the field sits inside something that already explains itself (a table cell, a group of filters), never to save space.
hintstring—
inputRefRef<HTMLTextAreaElement>The real `<textarea>`, to focus it, select its text or measure it from outside. It is separate from `ref` because the component paints a box with label, hint and error, and whoever asks for a ref almost always wants the control.
invalidboolean—
maxCountnumberA limit that WARNS without cutting: typing can go on, the count turns red, the field is marked invalid and how many are left over is announced. To cut off hard there is `maxLength`. With `maxCount` the counter shows even if not asked for.
maxRowsnumberHow many rows it grows to while typing; beyond that the scrollbar shows. By default, 20. With the same number as `rows` the field does not grow.
onChange(value: string) => void—
onChangeEvent(event: ChangeEvent<HTMLTextAreaElement>) => voidLike `onChange`, but with the native event of the `<textarea>`: `e.target.value`, `e.currentTarget`... It exists to migrate a front end that already writes its handlers with the event (AMS-735). If you only want the text, `onChange` already gives it to you.
placeholderstring—
readOnlyboolean—
requiredboolean—
resize"none" | "vertical"Whether it can be resized by hand: downwards (`vertical`, the default) or not at all (`none`). Not sideways, which breaks the grid.
rowsnumberRows shown at first (1 to 12). As more is typed, it grows by itself up to `maxRows`.
size"sm" | "md" | "lg"—
successstringThe confirmation that what was typed is valid. An error or a warning take precedence over it.
validationBehavior"aria" | "native"`aria` (the default) announces the state without the browser interrupting submission with its bubble; `native` also adds its own validation.
valuestring—
variantFieldVariant—
warningstringA warning that lets you go on, with its icon and colour, where the error would go. The field is still valid.

It also accepts the attributes of the element it renders: className, style, data-*, aria-* and its events.

In the test bench

Every state and variant, to try one at a time, on its page at storybook.amsetui.com: