Skip to main content

TextField

MD3 text field in filled and outlined variants, with floating label, supporting text, character counter, and multiline mode.

Variants​

<TextField
variant="outlined"
label="Email"
value={email}
onChange={(event) => setEmail(event.target.value)}
/>

Supporting text & error​

Visible to everyone
Too short

The native input​

ref points at the root element; use inputRef for the native control, and inputProps for attributes without a dedicated prop:

<TextField
label="Amount"
inputRef={inputRef}
inputProps={{ inputMode: 'decimal', pattern: '[0-9]*' }}
/>

Props​

PropTypeDefaultDescription
autoCompletestring—Native input `autoComplete`.
defaultValuestring—Uncontrolled initial value.
disabledbooleanfalseDisables the input and applies disabled styling.
endIconReactNode—Icon at the end of the field (decorative).
errorbooleanfalseError state — error colors, `aria-invalid`, and `errorText`. Ignored while `disabled`.
errorTextstring—Shown instead of `supportingText` (with `role="alert"`) when `error` is set.
getCounterLabel((length: number, maxLength: number) => string)(length: number, maxLength: number) => `Character count: ${length} of ${maxLength}`Accessible wording for the `maxLength` counter (the visible `3 / 20` is hidden from assistive tech in favor of this text).
idstring—Applied to the native input (keeps the floating label association via `htmlFor`).
inputPropsInputHTMLAttributes<HTMLInputElement> | TextareaHTMLAttributes<HTMLTextAreaElement>—Extra attributes spread on the native `<input>` (or `<textarea>` when `multiline`) — the escape hatch for attributes without a dedicated prop (`pattern`, `min`, `max`, `step`, `onKeyDown`, extra `aria-*`, …). Precedence: the component's own wiring always wins over conflicting `inputProps` keys — the controlled `value` / `onChange` / `onFocus` / `onBlur`, `id`, `className`, and every dedicated input prop the component sets (`type`, `name`, `placeholder`, `required`, `readOnly`, `autoComplete`, `maxLength`, `rows`, …).
inputRefRef<HTMLInputElement | HTMLTextAreaElement>—Ref to the native `<input>` / `<textarea>` element (the forwarded `ref` points at the root).
labelstring—Floating label; rendered with a trailing `*` when `required`.
maxLengthnumber—Native input `maxLength`; also shows a `length / maxLength` counter in the supporting line.
multilinebooleanfalseRender a `<textarea>` that auto-grows with its content.
namestring—Native input `name`.
onBlurFocusEventHandler<HTMLInputElement | HTMLTextAreaElement>—Blur handler for the input / textarea.
onChangeChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>—Native change handler for the input / textarea.
onFocusFocusEventHandler<HTMLInputElement | HTMLTextAreaElement>—Focus handler for the input / textarea.
placeholderstring—Native input `placeholder`.
prefixTextstring—Static text before the input value (e.g. currency symbol).
readOnlybooleanfalseNative input `readOnly`.
requiredbooleanfalseMarks the input required and appends `*` to the label.
rowsnumber2Initial visible rows of the `multiline` textarea.
startIconReactNode—Icon at the start of the field (decorative).
suffixTextstring—Static text after the input value (e.g. unit).
supportingTextstring—Helper line below the field. Replaced by `errorText` while in error.
typestringtextNative input `type` (single-line only).
valuestring—Controlled input value.
variantenumfilledContainer style.