DS0
Components

TextField

A single-line text input for collecting short-form user data like names, emails, or search queries.

Overview

TextField is a labeled single-line text input that supports validation, helper text, icons, and multiple HTML input types. It uses the Label component internally for consistent form labeling and follows WAI-ARIA patterns for full accessibility.

Please enter a valid email address.

Usage


export function Example() {
  return <TextField label="Email" type="email" placeholder="you@example.com" />;
}

Sizes

<TextField label="Small" size="sm" placeholder="Small" />
<TextField label="Medium" size="md" placeholder="Medium" />
<TextField label="Large" size="lg" placeholder="Large" />
SizeHeightUse When
sm32pxDense UIs, compact forms
md40pxDefault, most contexts
lg48pxProminent fields, touch targets

Input Types

<TextField label="Text" type="text" />
<TextField label="Email" type="email" />
<TextField label="Password" type="password" />
<TextField label="Search" type="search" />
<TextField label="Phone" type="tel" />
<TextField label="URL" type="url" />
<TextField label="Number" type="number" />

States

Required

<TextField label="Email" isRequired placeholder="you@example.com" />

Disabled

<TextField label="Name" isDisabled defaultValue="John Doe" />

Read Only

<TextField label="API Key" isReadOnly defaultValue="sk-abc123" />

Invalid

<TextField
  label="Email"
  isInvalid
  errorMessage="Please enter a valid email"
  defaultValue="not-an-email"
/>

Helper Text

<TextField
  label="Username"
  helperText="Must be 3-20 characters"
  placeholder="Choose a username"
/>

With Icons

<TextField label="Email" leftIcon={<MailIcon />} placeholder="you@example.com" />
<TextField label="Search" rightIcon={<SearchIcon />} placeholder="Search..." />

Accessibility

Keyboard Interactions

KeyAction
TabMoves focus into/out of the input
TypingEnters text

Screen Reader

  • On focus: announces label, input role, required state, and description
  • On error: error message is announced via role="alert"

ARIA

  • aria-invalid="true" — when invalid
  • aria-required="true" — when required
  • aria-disabled="true" — when disabled
  • aria-describedby — points to helper text or error message
  • Label connected via <label htmlFor={id}>

API Reference

Props

PropTypeDefaultDescription
labelstringVisible label text (required)
type'text' | 'email' | 'password' | 'search' | 'tel' | 'url' | 'number''text'HTML input type
placeholderstringPlaceholder text
valuestringControlled value
defaultValuestringUncontrolled default
isDisabledbooleanfalseDisables input
isRequiredbooleanfalseMarks as required
isReadOnlybooleanfalseMakes read-only
isInvalidbooleanfalseShows error state
helperTextstringHint text below input
errorMessagestringError text when invalid
leftIconReactNodeIcon inside input, left
rightIconReactNodeIcon inside input, right
size'sm' | 'md' | 'lg''md'Input size
classNamestringCSS classes on wrapper

AI Decision Guide

Use TextField when:

  • Collecting short text input (names, emails, search queries)
  • Single-line form fields
  • Any labeled text input need

Don't use TextField when:

  • Multi-line text input → use TextArea
  • Selecting from predefined options → use Select
  • Boolean toggle → use Checkbox or Switch
ComponentWhen to Use Instead
TextAreaMulti-line text input
SelectPredefined options
LabelUsed internally for the input label

On this page