Demos

A textarea with a label and placeholder.

Usage

Use a textarea for free text, such as notes for a clinician or a list of symptoms. For a single line, use an Input.

Import it from @workspace/ui/components/textarea.

Notes

  • The textarea grows with its content. Set max-h-* in className to cap it, and add resize-y if the reader should resize it.
  • Wrap it in a label, or link a label with id and htmlFor.
  • Use the placeholder for an example, not instructions the reader needs once they start typing.

Examples

Disabled

Text the reader can see but not change.

Invalid

Set aria-invalid to show an error, and put the message below.

Character count

Hold the value in state to show a count against maxLength.

Props

Takes every textarea prop. These are the ones you set most often.

Textarea

PropTypeDefaultDescription
placeholderstring—Hint shown when empty.
defaultValuestring—Text on first render.
valuestring—Text when controlled.
onChange(event) => void—Called on every change.
maxLengthnumber—Most characters allowed.
disabledbooleanfalseBlocks input and dims the field.
aria-invalidboolean—Shows the error style.