TextField

Text fields let people enter text into a UI.

Props

React props
NameTypeRequiredDefaultDescription
labelstringYesField label, floated above the value or notched into the outlined legend.
leadingIconIconNoOptional icon shown before the value.
supportingTextstringNoMessage shown below the field.
trailingIconIconNoOptional icon shown after the value. Defaults to a calendar indicator for `type="date"` and a chevron indicator for `type="select"`.
suffixstringNoStatic text appended after the value, for example a unit. Hidden while an error icon is shown.
typeTextFieldTypeNo'text'Native input kind, or a UI mode: `'date'` opens a date picker and `'select'` opens a menu of `options`.
classNamestring | Partial<Record<"content" | "input" | "label" | "legend" | "stateLayer" | "activeIndicator" | "leadingIcon" | "supportingText" | "textField" | "trailingIcon" | "suffix", string>> | ClassNameComponent<...>NoRoot classes (string), static element classes (object), or state-aware element classes (function).
defaultValuestringNoInitial value for uncontrolled usage.
autoFocusbooleanNoFocuses the field once, on mount.
idstringNoId of the underlying form control. Auto-generated if not provided.
onFocus() => voidNoFires when the underlying control gains focus.
onBlur() => voidNoFires when the underlying control loses focus.
onChange(value: string) => voidNoCalled once for each accepted value transition.
variantTextFieldVariantNo'filled'Visual style.
multilinebooleanNofalseSwitches to an auto-growing multiline textarea.
valuestringNoControlled value. Providing it makes the field controlled for its lifetime.
disabledbooleanNofalsePrevents interaction and form submission.
namestringNoName of the underlying form control.
placeholderstringNoPlaceholder shown only while the field is focused and empty.
autoCompletestringNo'on'Native autocomplete hint.
errorTextstringNoError message. Also switches the field to its error color treatment and shows an error icon.
showSupportingTextbooleanNocomputed from `errorText`/`supportingText`Forces the supporting text row.
mask(raw: string) => stringNoTransforms typed or pasted input into the value, on every keystroke -- for example inserting separators as digits accumulate, or rejecting characters outside an expected format (a card number, a phone number, an ID). Defaults to the built-in `YYYY-MM-DD` mask (`sanitizeTextFieldDateInput`) for `type="date"`; unset for every other type. Providing one for `type="date"` replaces the built-in mask. Must be idempotent (`mask(mask(x)) === mask(x)`): the field is controlled, so `mask` receives its own previous output back as `raw` on every subsequent keystroke. A literal you inject (a `+33` country code, a fixed digit group) will be mistaken for freshly typed input on the next call unless you strip it back out first -- inserted separators that aren't valid data characters (a `-`, a space) don't need this, since a naive filter already excludes them.
minstring | numberNoNative lower bound forwarded to the underlying input.
maxstring | numberNoNative upper bound forwarded to the underlying input.
stepstring | numberNoNative increment forwarded to the underlying input.