Currently brewing — dede is in beta: a first set of components, with more to come. The API may still change.

Textarea

A box for several lines of text.

import { Textarea } from "@dede-style/ui/textarea", then <Textarea value={v} onChange={setV} />. It is controlled: pass the text in value, and onChange gives you the new text as a string. Put it in a Field to give it a label.

The same box as Text Input, for longer text. It has the same edge, corners, focus ring, and disabled and read-only looks. Use it for a message, a note or an address. For one line, use Text Input.

It fills the width of its container. There is no width prop: to make it narrower, put it in a narrower column.

The person can drag the corner to make it taller. They cannot make it wider, or shorter than it starts.

Rows

rows sets the height in lines. It is 2, 3 (the default), 4, 5, 6 or 8.

  • rows={2}
  • rows={5}

rows is also the smallest the box can be. The person can drag it taller, but not shorter than rows. To remove the drag handle, set resize="none".

There is no rows={1}. A box one line tall looks like a Text Input, so use a Text Input instead.

Growing as you type

With autoSize, the box gets taller as the text gets longer.

It starts at rows and grows one line at a time. It never gets shorter than rows. There is no maximum height.

It uses the CSS property field-sizing: content. Chrome and Edge (version 123 and later), Safari (26.2 and later) and Firefox (152 and later) support it. In older browsers the box stays at rows and keeps its drag handle, so the person can still make it taller.

In a browser that grows the box, the drag handle is removed. A height the person dragged would stop the box growing.

In a form

A Text Input and two Textareas, each in a Field. Both Textareas use autoSize, so they grow as you type.

Where to leave the parcel if nobody is in.

Up to 500 characters.

Textarea has no label or help text of its own. The Field supplies them: the label above, a hint under the label, and an error message below the box. An error also turns the box’s edge red.

To limit the length, set maxLength and say the limit in the hint. The Message box above has maxLength={500} and the hint “Up to 500 characters.” The browser stops typing at 500. There is no live counter, so the hint is the only place the person learns the limit.

A Textarea and a Text Input of the same size line up. The first line of text sits the same distance from the top of the box, and the text is the same size.

Giving it a name

Every Textarea needs a name for screen readers. It comes from a Field or from aria-label.

  • in a Field
  • aria-label

In a form, use a Field. The Field’s label is the name, and everyone can see it. The Field also links the hint and the error to the box, and marks the box invalid when there is an error. You do not set an id or any ARIA yourself.

Without a Field, set aria-label. Screen readers read it, but nobody else sees it. Use it only where the box’s purpose is clear from what is around it. Inside a Field, leave it off.

A placeholder is not a name. It disappears as soon as the person types, so put anything they still need in the label or the hint.