New contact
Text fields let people enter text into a UI, such as contact or payment information. They commonly appear in forms and dialogs.
To type a date, use a date field, and to search, a search bar.
import { TextField } from '@material-web/react'Basic text field
Set the label text with label and the supporting text with description, and put icons around the input with leading and trailing. A text field takes no children.
import { Icon, IconButton, TextField } from '@material-web/react'
import { useState } from 'react'
export default function Basic() {
const [amount, setAmount] = useState('12.50')
return (
<TextField
variant="outlined"
label="Amount"
description="Before tax"
name="amount"
inputMode="decimal"
isRequired
maxLength={8}
prefix="€"
value={amount}
onChange={setAmount}
trailing={
<IconButton aria-label="Clear" onPress={() => setAmount('')}>
<Icon name="cancel" />
</IconButton>
}
className="w-64"
/>
)
}The TextField comes in two variants: set variant to filled (the default) or outlined. Both work the same way, so choose between them by style. Use one variant within a region, and do not mix the two there.
import { TextField } from '@material-web/react'
export default function Variants() {
return (
<>
<TextField variant="filled" label="Filled" description="Supporting text" className="w-64" />
<TextField
variant="outlined"
label="Outlined"
description="Supporting text"
className="w-64"
/>
</>
)
}Filled text field
A filled text field has more visual emphasis than an outlined one, which makes it stand out among other content and components.
import { TextField } from '@material-web/react'
export default function Filled() {
return (
<>
<TextField variant="filled" label="Filled" description="Supporting text" className="w-64" />
<TextField variant="filled" label="Disabled" isDisabled className="w-64" />
</>
)
}Outlined text field
An outlined text field has less visual emphasis, which helps simplify a layout where many fields are placed together, such as a form.
import { TextField } from '@material-web/react'
export default function Outlined() {
return (
<>
<TextField
variant="outlined"
label="Outlined"
description="Supporting text"
className="w-64"
/>
<TextField variant="outlined" label="Disabled" isDisabled className="w-64" />
</>
)
}Label and supporting text
Set label to the label text, which names the field. The label rests on the input's line until the field is focused or holds text, and then moves to the top of the field. Set description to the supporting text, which is shown under the field and describes it.
Set placeholder to show a hint while the field is empty. In a field with a label, the placeholder shows only once the field is focused.
Pressing the label focuses the input, and so does pressing anywhere in the field that is not another control, such as an icon button.
import { TextField } from '@material-web/react'
export default function LabelAndSupportingText() {
return (
<>
<TextField
label="Username"
description="Letters and numbers only"
placeholder="ada1815"
className="w-64"
/>
<TextField
variant="outlined"
label="Username"
description="Letters and numbers only"
defaultValue="ada1815"
className="w-64"
/>
</>
)
}Without a label
A field with no label can be named by a separate, adjacent label: set aria-labelledby to that label's id. With neither, set an aria-label. Without a label, the placeholder shows whenever the field is empty.
import { Icon, TextField } from '@material-web/react'
export default function WithoutLabel() {
return (
<div className="flex flex-wrap items-end justify-center gap-space-200">
<div className="flex flex-col gap-space-100">
<span id="full-name" className="text-body-lg text-on-surface">
Full name
</span>
<TextField
variant="outlined"
aria-labelledby="full-name"
placeholder="Ada Lovelace"
className="w-64"
/>
</div>
<TextField
type="search"
aria-label="Search"
placeholder="Search"
leading={<Icon name="search" />}
className="w-64"
/>
</div>
)
}Icons
Set leading and trailing to the field's leading and trailing icons. Each takes one icon, icon button or 24dp image, and shows it at the start or the end of the field.
- An icon button is a tab stop after the input. Give it an
aria-labelthat says what it does. It is disabled with the field, unless it setsisDisabled={false}itself. - A value that renders nothing shows no icon, so an icon can be conditional:
trailing={invalid && <Icon name="error" />}. In this example, the clear icon appears only while there is text to clear.
import { Icon, IconButton, TextField } from '@material-web/react'
import { useState } from 'react'
export default function Icons() {
const [isShown, setShown] = useState(false)
const [query, setQuery] = useState('Material')
return (
<>
<TextField
label="Password"
type={isShown ? 'text' : 'password'}
autoComplete="current-password"
className="w-64"
leading={<Icon name="lock" />}
trailing={
<IconButton
aria-label={isShown ? 'Hide password' : 'Show password'}
onPress={() => setShown(!isShown)}
>
<Icon name={isShown ? 'visibility_off' : 'visibility'} />
</IconButton>
}
/>
<TextField
variant="outlined"
label="Search"
type="search"
value={query}
onChange={setQuery}
className="w-64"
leading={<Icon name="search" />}
trailing={
query !== '' && (
<IconButton aria-label="Clear" onPress={() => setQuery('')}>
<Icon name="cancel" />
</IconButton>
)
}
/>
</>
)
}Prefix and suffix
Set prefix and suffix to show text on the input's line, before and after the input text: prefix="€", suffix="@gmail.com". In a field with a label, they show once the field is focused or holds text. They are shown as written and do not describe the input.
import { TextField } from '@material-web/react'
export default function PrefixAndSuffix() {
return (
<>
<TextField
label="Amount"
inputMode="decimal"
defaultValue="12.50"
prefix="€"
className="w-48"
/>
<TextField label="Weight" inputMode="numeric" suffix="lbs" className="w-48" />
<TextField variant="outlined" label="Email" suffix="@gmail.com" className="w-48" />
</>
)
}State functions
Pass a function as leading, trailing, prefix or suffix to render it from the field's state: isHovered, isFocusWithin, isFocusVisible, isDisabled and isInvalid. isFocusWithin is true while the input has the focus, from the pointer too. The state's type is exported as TextFieldRenderProps.
import { Icon, TextField } from '@material-web/react'
import { useState } from 'react'
export default function RenderProps() {
const [name, setName] = useState('ada lovelace')
return (
<TextField
variant="outlined"
label="Username"
description="No spaces"
value={name}
onChange={setName}
isInvalid={name.includes(' ')}
className="w-64"
leading={({ isFocusWithin }) => (
<Icon name="person" className={isFocusWithin ? 'icon-filled' : undefined} />
)}
trailing={({ isInvalid }) =>
isInvalid && <Icon name="error" className="icon-filled" aria-label="Error" />
}
/>
)
}Multiline
Set lines to choose how the field displays its text:
single(the default) displays one line of text.multistarts at the height of itsrowsand grows with its text.areakeeps the height of itsrowsand scrolls.
import { TextField } from '@material-web/react'
const note =
'This is a long input that wraps overflow text onto a new line, past the height of the text area.'
export default function Lines() {
return (
<div className="flex flex-wrap items-start justify-center gap-space-200">
<TextField label="Multi-line" lines="multi" defaultValue={note} className="w-64" />
<TextField
variant="outlined"
label="Text area"
lines="area"
rows={3}
defaultValue={note}
className="w-64"
/>
</div>
)
}Without rows, a multi field starts as one line and an area is two lines tall.
Controlled
Set the initial text with defaultValue, and the field keeps its text itself. To keep the text in your own state, control the field with value and onChange, which is called with the new text and not with an event.
import { TextField } from '@material-web/react'
import { useState } from 'react'
export default function Controlled() {
const [name, setName] = useState('Ada')
return (
<>
<TextField label="Uncontrolled" defaultValue="Ada" className="w-48" />
<TextField label="Controlled" value={name} onChange={setName} className="w-48" />
<span className="text-body-md text-on-surface-variant">
{name === '' ? 'No name yet' : `Hello, ${name}`}
</span>
</>
)
}Color
A focused field draws its label, its caret and its active indicator or outline in the primary color role. To use another color, set that role on the field in your own CSS. The value applies to everything inside the field. See Theme.
.field-tertiary {
--md-sys-color-primary: var(--md-sys-color-tertiary);
}<TextField label="Name" className="field-tertiary" />Widths
Set the field's width in className, such as w-64, or w-full to make the field as wide as the element it is in. Without a width, the field is as wide as the browser's default input.
import { TextField } from '@material-web/react'
export default function FullWidth() {
return <TextField variant="outlined" label="Address" className="w-full" />
}Form props
A text field takes the standard form props, such as name, type, placeholder, isRequired, isReadOnly, isDisabled, maxLength and autoFocus. For the error state, see Validation.
Required
Set isRequired to end the label with an asterisk, which becomes part of the field's name. Use the supporting text to say what the asterisk means.
import { TextField } from '@material-web/react'
export default function Required() {
return <TextField label="Username" description="*required" isRequired className="w-64" />
}Read-only and disabled
Set isReadOnly to make the field read-only. A read-only field looks the same as any other, so label it as read-only. Set isDisabled to disable the field and any icon button in it.
import { TextField } from '@material-web/react'
export default function ReadOnlyAndDisabled() {
return (
<>
<TextField
label="Order number"
description="Read-only"
defaultValue="CA-2026-10-0417"
isReadOnly
className="w-64"
/>
<TextField
variant="outlined"
label="Coupon"
description="Not available for this order"
defaultValue="SPRING"
isDisabled
className="w-64"
/>
</>
)
}Character counter
Set maxLength to also show a character counter after the supporting text: the characters used over the limit. It counts a controlled field's value, or an uncontrolled field's defaultValue and what is typed into it.
Set counterLabel to the text a screen reader reads before the counter's numbers. It is Character count by default.
import { TextField } from '@material-web/react'
export default function CharacterCounter() {
return (
<TextField
label="Display name"
description="Shown on your profile"
defaultValue="Ada"
maxLength={20}
className="w-64"
/>
)
}Controlling the HTML input
The props of an <input> that a text field takes go to its <input>: id, name, type, inputMode, autoComplete, autoCapitalize, pattern, minLength, maxLength, enterKeyHint and spellCheck. Set inputRef for a ref to the <input>, or to the <textarea> when lines is multi or area.
<TextField label="Amount" inputMode="decimal" enterKeyHint="done" inputRef={inputRef} />className, style, ref and a data-* attribute go to the field's outermost element instead. See Customization.
Input types
Set type to the type of the input. With text, search, url, tel, email, password and number, the label rests on the input's line while the field is empty. With any other type, such as date or time, the label stays at the top of the field.
A search input does not show the browser's own clear button or magnifier. Add these icons with leading and trailing.
import { TextField } from '@material-web/react'
export default function InputTypes() {
return (
<>
<TextField label="Date" type="date" className="w-48" />
<TextField label="Time" type="time" className="w-48" />
<TextField label="Quantity" type="number" placeholder="0" className="w-48" />
</>
)
}Validation
Set isInvalid to put the field in the error state. Pass the error text as description while the field is invalid: it replaces the supporting text and is announced as an alert. Add an error icon as a second cue. A trailing icon takes the error color, and one that is not a button needs an aria-label, such as Error.
In this example, the field is controlled, and is invalid while its text is not an email address.
import { Icon, TextField } from '@material-web/react'
import { useState } from 'react'
export default function ErrorState() {
const [email, setEmail] = useState('name@')
const isInvalid = email !== '' && !/^\S+@\S+\.\S+$/.test(email)
return (
<TextField
variant="outlined"
label="Email"
type="email"
value={email}
onChange={setEmail}
isInvalid={isInvalid}
description={isInvalid ? 'Enter an address such as name@example.com' : 'Used to sign in'}
trailing={isInvalid && <Icon name="error" className="icon-filled" aria-label="Error" />}
className="w-80"
/>
)
}The field also shows the messages of React Aria's validation: those that validate returns, and the browser's own for native constraints such as isRequired. They show once the form is submitted, or as the text changes when validationBehavior is aria. While the field is invalid, they replace the supporting text as the error text and are announced as an alert. A field that is invalid with no message shows its description as the error text.
<TextField
label="Username"
description="At least 3 characters"
validationBehavior="aria"
validate={(text) => (text.length < 3 ? 'Enter at least 3 characters' : null)}
/>A field in a form is also validated when the form is submitted. See Forms.
Forms
Set a name to include the field in a form. It is submitted and validated with the form, and its text and counter are reset with it.
Validation is native unless validationBehavior is aria. A required field left empty, or a field that is isInvalid, blocks its form from being submitted. A field its form finds invalid on submit shows the error state, with the browser's validation message as the error text, until its text is changed and the field loses the focus, or until the form is reset. See React Aria's Forms guide.
import { Button, TextField } from '@material-web/react'
import { useState } from 'react'
export default function Form() {
const [sent, setSent] = useState<string>()
return (
<form
className="flex w-80 flex-col gap-space-200"
onSubmit={(event) => {
event.preventDefault()
setSent(JSON.stringify(Object.fromEntries(new FormData(event.currentTarget))))
}}
>
<span className="text-body-md text-on-surface-variant">*indicates a required field</span>
<TextField variant="outlined" label="Name" name="name" autoComplete="name" isRequired />
<TextField variant="outlined" label="Email" name="email" type="email" autoComplete="email" />
<TextField
variant="outlined"
label="Message"
name="message"
lines="area"
rows={4}
maxLength={200}
/>
<div className="flex justify-end gap-space-100">
<Button type="reset" variant="text" onPress={() => setSent(undefined)}>
Reset
</Button>
<Button type="submit">Send</Button>
</div>
{sent && <output className="text-body-sm text-on-surface-variant">{sent}</output>}
</form>
)
}Customization
Pass classes in className to size and place one field. See Styling for the classes, the states and the theme.
- Element: A text field is an inline flex box, aligned to the top of its line.
className,styleandrefapply to its outermost element, so set its width and position there.inputRefapplies to its<input>, or to its<textarea>whenlinesismultiorarea. - States: On the field, style the disabled, invalid, read-only and required states with their variants, such as
invalid:. Hover and focus are reported inside the field: use thehas-*form for them, as inhas-hover:bg-surface-container. See Variants. - Text inputs: The
populated:variant matches a text input that holds text, that is, one not showing its placeholder. - Functions:
classNameandstylecan be functions ofisDisabled,isInvalid,isReadOnlyandisRequired. For hover and focus, pass a state function asleading,trailing,prefixorsuffix. - Every field: To restyle all the text fields at once, change the theme.
In your own CSS, target these attributes:
| Element | Attributes |
|---|---|
| Outermost element | data-disabled, data-invalid, data-readonly and data-required |
| Container around the input and its icons | data-hovered, data-focus-within, data-focus-visible, data-disabled and data-invalid |
| Input | data-focused whenever it has the focus, from the pointer too, and data-hovered, data-focus-visible, data-disabled and data-invalid |
Density
A text field is 56dp tall, and has no size prop. Add the density-1, density-2 or density-3 class of the theme's spacing to the field, or to an element around it, to make the field 4dp shorter for each step.
import { TextField } from '@material-web/react'
export default function Density() {
return (
<>
<TextField variant="outlined" label="Default" defaultValue="56dp" className="w-40" />
<TextField
variant="outlined"
label="density-1"
defaultValue="52dp"
className="w-40 density-1"
/>
<TextField
variant="outlined"
label="density-2"
defaultValue="48dp"
className="w-40 density-2"
/>
<TextField
variant="outlined"
label="density-3"
defaultValue="44dp"
className="w-40 density-3"
/>
</>
)
}Don't apply density to text fields by default: this lowers their targets below the recommended 48 by 48 CSS pixels. Instead, give people a way to choose a higher density, like selecting a denser layout or changing the theme.
Custom input
Pass a function to input to render an <input> of your own in place of the field's, such as one with an attribute that the field does not take, like list. It is called with the props to spread on your element, including ref, and with the input's state, such as isFocused and isInvalid. When lines is multi or area, it renders the <textarea> instead.
In this example, the input suggests values from a list.
import { TextField } from '@material-web/react'
export default function CustomInput() {
return (
<>
<TextField
label="City"
input={(props) => <input {...props} list="cities" />}
className="w-64"
/>
<datalist id="cities">
<option value="Calgary" />
<option value="Edmonton" />
<option value="Vancouver" />
</datalist>
</>
)
}Limitations
Floating label
The raised label of an outlined field extends above the field's top edge. If a scrolling box starts with an outlined field, give the box pt-space-100 so that the label is not cut off.
A label wider than the field is cut off with an ellipsis, so keep it short.
Supporting text
Supporting text and the character counter make the field taller. In a row where only some fields have them, align the fields to the top, as with items-start, so that their containers line up.
Disabled fieldset
A field in a disabled <fieldset> cannot be edited, but its label and text keep their enabled colors, and it does not report the disabled state. Set isDisabled on the field as well.
Use cases
Material lists what people should be able to do with assistive technology:
- Navigate to and activate a text field with assistive technology
- Input information into the text field
- Receive and understand supporting text and error messages
- Navigate to and select interactive icons
Interaction and style
- States: Hovering a filled field shows a state layer, and hovering an outlined field darkens its outline. A focused field raises its label and draws its active indicator or outline 3dp thick in the primary color, whether the focus comes from the keyboard or a press. An invalid field draws them in the error color.
- Touch target: An icon button in the field keeps its 48dp touch target, inside the field.
- Color contrast: With the default color roles, the active indicator and the outline keep 3:1 contrast with the surface in every scheme, and the label, the input text and the supporting text keep 4.5:1. Material advises at least 3:1 between an outline and the background. Keep it when you change the field's colors.
- Density: Each density step makes the field 4dp shorter, down to 44dp at the third.
- Motion: With reduced motion, the label moves and the colors change at once.
- Forced colors: In forced colors, a filled field keeps an edge, a focused field draws its indicator or outline in the system's highlight color, and a disabled field is grayed out.
- Right to left: The layout is mirrored in a right-to-left direction, with the leading icon on the right.
Focus
- A press on the label, or anywhere in the field that is not another control, focuses the input.
- A disabled field cannot be focused, and neither can an icon button in it. A read-only field can be focused.
Keyboard navigation
| Keys | Actions |
|---|---|
| Tab | Move the focus to the input, and then to an icon button in the field |
| Space or Enter | Press the focused icon button |
Labeling elements
- The input is a text box named by the
label, including the asterisk of a required field, as Material advises. Without alabel, set anaria-labeloraria-labelledby. - The
descriptiondescribes the field. While the field is invalid, the error text describes it instead and is announced as an alert. - The character counter also describes the field, after the supporting text and before the elements of your own
aria-describedby. A screen reader reads thecounterLabelbefore its numbers: Character count by default. - Give an icon button in the field an
aria-labelthat says what it does, and that follows its state. Material's example is Show password, and Hide password while the password is shown. An icon that is not a button, such as an error icon, needs anaria-labeltoo, such as Error. - A prefix and a suffix are shown as written and do not describe the input. Where the symbol matters, such as € for euros, say it in the
labelor thedescriptionas well.
Note: A description added after the field first renders is shown, but does not describe the field until the error state next changes.
variant'filled' | 'outlined'Default'filled'There are two variants of text fields:
- Filled text fields
- Outlined text fields
Both variants of text fields use a container to provide a visual cue for interaction and provide the same functionality.
Outlined text fields have less visual emphasis than filled text fields. When they appear in places like forms (where many text fields are placed together), their reduced emphasis helps simplify the layout.
If both variants of text field are used in a UI, they should be used consistently within different sections, and not intermixed within the same region.
labelReactNodeLabel text tells people what information is requested. Every text field should have a label.
Label text should be aligned with the input text, and always visible. It can be placed in the middle of a text field, or rest near the top of the container.
Label text shouldn't be truncated or take up multiple lines. Keep it short, clear, and fully visible.
A text field doesn't require a label if the field's purpose is indicated by a separate, adjacent label.
If a text field requires input, indicate so with an asterisk at the end of the text field label. The accessibility label must include the asterisk.
descriptionReactNodeSupporting text conveys additional information about the input field, such as how it will be used. It should ideally be one line, though may wrap to multiple lines if required. It can be either persistently visible or visible only on focus.
For text fields that validate their content such as passwords, replace supporting text with error text. Swapping supporting text with error text prevents new lines of text from bumping content and changing the layout.
When there is an error, "alert" is applied to the role and the error message to the text label.
counterLabelstringDefault'Character count'The accessibility label for the character counter clarifies the number of characters that can be entered into the text field.
The remaining character counter should be called “character count” within the label
leadingAriaGroupProps['children']Leading icon (optional)
Icons in text fields are optional. Text field icons can:
- Describe valid input methods such as a microphone icon
- Provide affordances to access additional functionality such as clearing the content of a field
- Express an error
Leading and trailing icons change their position based on LTR or RTL contexts.
Icon signifiers can describe the type of input a text field requires, and be touch targets for nested components. For example, a calendar icon may be tapped to reveal a date picker.
trailingAriaGroupProps['children']Trailing icon (optional)
It’s strongly recommended to show an error icon when the text field is in the error state.
This highlights the error for people with visual impairments, and provides an additional sensory indicator.
Clear icons let a person clear an entire input field. They appear only when input text is present.
A dropdown arrow indicates that a text field has a nested selection component.
Images that are 24dp in height can be placed inside of text fields. This image height allows for optimal top and bottom padding within the field and is consistent with icon size recommendations.
For text fields with interactive trailing icons, the accessibility label clarifies its function.
When an icon has no actionable role, like an error icon, the label is "Error."
prefixAriaGroupProps['children']Text fields can contain prefix text such as currency symbol.
The prefix and suffix of a text field provides symbols and abbreviations to help users enter the correct values.
suffixAriaGroupProps['children']Text fields can contain suffix text such as unit of measurement or email domain.
The prefix and suffix of a text field provides symbols and abbreviations to help users enter the correct values.
lines'single' | 'area' | 'multi'Default'single'Text fields can display input text in the following ways:
- Single line text fields display only one line of text
- Multi-line text fields grow to accommodate multiple lines of text
- Text areas are fixed-height fields
In multi-line fields, overflow text causes the text field to expand, shifting screen elements downward and text wraps onto a new line. These fields initially appear as single-line fields, which is useful for compact layouts that need to accommodate large amounts of text.
Text areas are taller than text fields and wrap overflow text onto a new line. They are a fixed height and scroll vertically when the cursor reaches the bottom of the field. The large initial size indicates that longer responses are possible and encouraged. These should be used instead of multi-line fields on the web.
Props of TextField (56)
classNameClassNameOrFunction<TextFieldRenderProps>Default'react-aria-TextField'The CSS className for the element. A function may be provided to compute the class based on component state.
isInvalidbooleanWhether the value is invalid.
formstringThe
<form>element to associate the input with. The value of this attribute must be the id of a<form>in the same document. See MDN.patternstringRegex pattern that the value of the input must match to be valid. See MDN.
idstringThe element's unique identifier. See MDN.
aria-labelstringDefines a string value that labels the current element.
aria-labelledbystringIdentifies the element (or elements) that labels the current element.
aria-describedbystringIdentifies the element (or elements) that describes the object.
aria-detailsstringIdentifies the element (or elements) that provide a detailed, extended description for the object.
isDisabledbooleanWhether the input is disabled.
autoFocusbooleanWhether the element should receive focus on render.
onFocus(e: FocusEvent<Target>) => voidHandler that is called when the element receives focus.
onBlur(e: FocusEvent<Target>) => voidHandler that is called when the element loses focus.
onFocusChange(isFocused: boolean) => voidHandler that is called when the element's focus status changes.
onKeyDown(e: KeyboardEvent) => voidHandler that is called when a key is pressed.
onKeyUp(e: KeyboardEvent) => voidHandler that is called when a key is released.
aria-haspopup'dialog' | 'menu' | 'true' | 'false' | 'grid' | 'listbox' | 'tree' | booleanIndicates the availability and type of interactive popup element, such as menu or dialog, that can be triggered by an element.
aria-controlsstringIdentifies the element (or elements) whose contents or presence are controlled by the current element.
type'text' | 'search' | 'url' | 'tel' | 'email' | 'password' | (string & {})Default'text'The type of input to render. See MDN.
namestringThe name of the input element, used when submitting an HTML form. See MDN.
valuestringThe current value (controlled).
excludeFromTabOrderbooleanWhether to exclude the element from the sequential tab order. If true, the element will not be focusable via the keyboard by tabbing. This should be avoided except in rare scenarios where an alternative means of accessing the element or its functionality via the keyboard is available.
onChange(value: string) => voidHandler that is called when the value changes.
isReadOnlybooleanWhether the input can be selected but not changed by the user.
defaultValuestringThe default value (uncontrolled).
isRequiredbooleanWhether user input is required on the input before form submission.
validate(value: string) => true | ValidationError | null | undefinedA function that returns an error message if a given value is invalid. Validation errors are displayed to the user when the form is submitted if
validationBehavior="native". For realtime validation, use theisInvalidprop instead.aria-errormessagestringIdentifies the element that provides an error message for the object.
autoCompletestringDescribes the type of autocomplete functionality the input should provide if any. See MDN.
enterKeyHint'search' | 'enter' | 'done' | 'go' | 'next' | 'previous' | 'send'An enumerated attribute that defines what action label or icon to preset for the enter key on virtual keyboards. See MDN.
spellCheckstringAn enumerated attribute that defines whether the element may be checked for spelling errors. See MDN.
autoCorrectstringAn attribute that takes as its value a space-separated string that describes what, if any, type of autocomplete functionality the input should provide. See MDN.
inputMode'search' | 'text' | 'none' | 'tel' | 'url' | 'email' | 'numeric' | 'decimal'Hints at the type of data that might be entered by the user while editing the element or its contents. See MDN.
aria-activedescendantstringIdentifies the currently active element when DOM focus is on a composite widget, textbox, group, or application.
aria-autocomplete'none' | 'list' | 'inline' | 'both'Indicates whether inputting text could trigger display of one or more predictions of the user's intended value for an input and specifies how predictions would be presented if they are made.
onCopyClipboardEventHandler<HTMLInputElement>Handler that is called when the user copies text. See MDN.
onCutClipboardEventHandler<HTMLInputElement>Handler that is called when the user cuts text. See MDN.
onPasteClipboardEventHandler<HTMLInputElement>Handler that is called when the user pastes text. See MDN.
onCompositionEndCompositionEventHandler<HTMLInputElement>Handler that is called when a text composition system completes or cancels the current text composition session. See MDN.
onCompositionStartCompositionEventHandler<HTMLInputElement>Handler that is called when a text composition system starts a new text composition session. See MDN.
onCompositionUpdateCompositionEventHandler<HTMLInputElement>Handler that is called when a new character is received in the current text composition session. See MDN.
onBeforeInputFormEventHandler<HTMLInputElement>Handler that is called when the input value is about to be modified. See MDN.
onInputFormEventHandler<HTMLInputElement>Handler that is called when the input value is modified. See MDN.
onSelectReactEventHandler<HTMLInputElement>Handler that is called when text in the input is selected. See MDN.
maxLengthnumberThe maximum number of characters supported by the input. See MDN.
minLengthnumberThe minimum number of characters required by the input. See MDN.
validationBehavior'native' | 'aria'Default'native'Whether to use native HTML form validation to prevent form submission when the value is missing or invalid, or mark the field as required or invalid via ARIA.
slotstring | nullA slot name for the component. Slots allow the component to receive props from a parent component. An explicit
nullvalue indicates that the local props completely override all props received from a parent.styleCSSProperties | (values: TextFieldRenderProps & { defaultStyle: CSSProperties; }) => CSSProperties | undefinedThe inline style for the element. A function may be provided to compute the style based on component state.
renderDOMRenderFunction<'div', TextFieldRenderProps>Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components.
Requirements:
- You must render the expected element type (e.g. if
<button>is expected, you cannot render an<a>). - Only a single root DOM element can be rendered (no fragments).
- You must pass through props and ref to the underlying DOM element, merging with your own prop as appropriate.
- You must render the expected element type (e.g. if
autoCapitalize'off' | 'none' | 'on' | 'sentences' | 'words' | 'characters'Controls whether inputted text is automatically capitalized and, if so, in what manner. See MDN.
refRef<HTMLDivElement>placeholderstringrowsundefinedinputRefRef<HTMLInputElement>inputAriaInputProps['render']
TextField also takes the 70 attributes and events of the element it renders.