Demos

A labelled text field.

Usage

Use an input for short free text: a name, an email, a number. For long text, use a textarea. Every input needs a visible label.

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

Anatomy

  • Input — A styled input element. All native attributes work. size is sm, default, or lg.

Notes

  • A placeholder is not a label. It disappears as soon as the reader types.
  • Set the right type and inputMode so phones show the right keyboard.
  • Set aria-invalid to show the error style. Put the error message right below the field.
  • Match size to the button next to it. Both use h-8, h-10, and h-12.
  • Disabled fields are skipped by the keyboard. Use readOnly if the reader should still be able to copy the value.

Examples

Sizes

sm, default, and lg. Match the size of a button next to it.

Number

For numbers, such as weight or a dose, use a Number Field. It adds step buttons, arrow keys, limits, and number formatting.

File

Restrict the picker with accept.

Invalid

Set aria-invalid and show the error below the field.

Disabled

A field the reader can see but not change.

With button

An input and its action in one row.

Props

These are the props you set most often. Unlisted props pass through to the input element.

Input

PropTypeDefaultDescription
size"sm", "default", or "lg"defaultHeight, padding, and text size.
typestringtextNative input type.
placeholderstring—Hint shown when the field is empty.
disabledbooleanfalseBlocks input and dims the field.
readOnlybooleanfalseKeeps the value selectable but not editable.
aria-invalidboolean—Shows the error style.
classNamestring—Classes merged onto the element.