Text field
Text fields let users enter and edit text.
Introduction
Text fields allow users to enter text into a UI. They typically appear in forms and dialogs.
<TextField />
Playground
Component
After installation, you can start building with this component using the following basic elements:
import TextField from '@mui/joy/TextField';
export default function MyApp() {
return <TextField placeholder="Search anything…" />;
}
Variants
The text field component supports the four global variants: solid (default), soft, outlined, and plain.
<TextField label="Solid" placeholder="Type in here…" variant="solid" />
<TextField label="Soft" placeholder="Type in here…" variant="soft" />
<TextField label="Outlined" placeholder="Type in here…" variant="outlined" />
<TextField label="Plain" placeholder="Type in here…" variant="plain" />
<TextField size="sm" label="Size" placeholder="Small" />
<TextField size="md" label="Size" placeholder="Medium" />
<TextField size="lg" label="Size" placeholder="Large" />
Form props
Standard form attributes are supported e.g. required
, disabled
, type
, etc. as well as a helperText
which is used to give context about a field's input, such as how the input will be used.
This is a helper text
<TextField label="Label" placeholder="Type in here…" required />
<TextField label="Label" placeholder="Type in here…" disabled />
<TextField
label="Label"
placeholder="Type in here…"
helperText="This is a helper text"
/>
Validation
To toggle the error state, use the error
prop. And, to provide feedback about the error to the user, use the helperText
prop.
You got this wrong. Try again!
<TextField
label="Label"
placeholder="Type in here…"
error
helperText="You got this wrong. Try again!"
/>
Input decorators
Use the startDecorator
and/or endDecorator
props to add supporting icons or elements to the text field.
<TextField label="Label" placeholder="Type in here…" fullWidth />
Unstyled
The component also comes with an unstyled version. It's ideal for doing heavy customizations and minimizing bundle size.