TextField API
API reference docs for the React TextField component. Learn about the props, CSS, and other APIs of this exported module.
Demos
For examples and details on the usage of this React component, visit the component demo pages:
Import
import TextFieldfrom'@mui/material/TextField';// orimport{ TextField}from'@mui/material';
Learn about the difference byreading this guide on minimizing bundle size.
TheTextField
is a convenience wrapper for the most common cases (80%).It cannot be all things to all people, otherwise the API would grow out of control.
Advanced Configuration
It's important to understand that the text field is a simple abstractionon top of the following components:
If you wish to alter the props applied to theinput
element, you can do so as follows:
const inputProps={step:300,};return<TextFieldid="time"type="time"inputProps={inputProps}/>;
For advanced cases, please look at the source of TextField by clicking on the"Edit this page" button above. Consider either:
- using the upper case props for passing values directly to the components
- using the underlying components directly as shown in the demos
Props of theFormControl component are also available.
Name | Type | Default | Description |
---|---|---|---|
autoComplete | string | - | This prop helps users to fill forms faster, especially on mobile devices. The name can be confusing, as it's more like an autofill. You can learn more about itfollowing the specification. |
autoFocus | bool | false | If |
classes | object | - | Override or extend the styles applied to the component. SeeCSS classes API below for more details. |
color | 'primary' | 'secondary' | 'error' | 'info' | 'success' | 'warning' | string | 'primary' | The color of the component. It supports both default and custom theme colors, which can be added as shown in thepalette customization guide. |
defaultValue | any | - | The default value. Use when the component is not controlled. |
disabled | bool | false | If |
error | bool | false | If |
FormHelperTextProps | object | - | Props applied to the Deprecated-Use slotProps.formHelperText instead. This prop will be removed in a future major release. SeeMigrating from deprecated APIs for more details. |
fullWidth | bool | false | If |
helperText | node | - | The helper text content. |
id | string | - | The id of the |
InputLabelProps | object | - | Props applied to the Deprecated-Use slotProps.inputLabel instead. This prop will be removed in a future major release. SeeMigrating from deprecated APIs for more details. |
inputProps | object | - | Attributes applied to the Deprecated-Use slotProps.htmlInput instead. This prop will be removed in a future major release. SeeMigrating from deprecated APIs for more details. |
InputProps | object | - | Props applied to the Input element. It will be a Deprecated-Use slotProps.input instead. This prop will be removed in a future major release. SeeMigrating from deprecated APIs for more details. |
inputRef | ref | - | Pass a ref to the |
label | node | - | The label content. |
margin | 'dense' | 'none' | 'normal' | 'none' | If |
maxRows | number | string | - | Maximum number of rows to display when multiline option is set to true. |
minRows | number | string | - | Minimum number of rows to display when multiline option is set to true. |
multiline | bool | false | If |
name | string | - | Name attribute of the |
onChange | func | - | Callback fired when the value is changed. Signature: function(event: object) => void
|
placeholder | string | - | The short hint displayed in the |
required | bool | false | If |
rows | number | string | - | Number of rows to display when multiline option is set to true. |
select | bool | false | Render a |
SelectProps | object | - | Props applied to the Deprecated-Use slotProps.select instead. This prop will be removed in a future major release. SeeMigrating from deprecated APIs for more details. |
size | 'medium' | 'small' | string | 'medium' | The size of the component. |
slotProps | { formHelperText?: func | object, htmlInput?: func | object, input?: func | object, inputLabel?: func | object, select?: func | object } | {} | The props used for each slot inside. |
slots | { formHelperText?: elementType, htmlInput?: elementType, input?: elementType, inputLabel?: elementType, root?: elementType, select?: elementType } | {} | The components used for each slot inside. |
sx | Array<func | object | bool> | func | object | - | The system prop that allows defining system overrides as well as additional CSS styles. See the`sx` page for more details. |
type | string | - | Type of the |
value | any | - | The value of the |
variant | 'filled' | 'outlined' | 'standard' | 'outlined' | The variant to use. |
Inheritance
While not explicitly documented above, the props of theFormControl component are also available in TextField. You can take advantage of this totarget nested components.
Theme default props
You can useMuiTextField
to change the default props of this componentwith the theme.
Slot name | Class name | Default component | Description |
---|---|---|---|
root | .MuiTextField-root | FormControl | The component that renders the root. |
input | OutlinedInput | The component that renders the input. | |
inputLabel | InputLabel | The component that renders the input's label. | |
htmlInput | 'input' | The html input element. | |
formHelperText | FormHelperText | The component that renders the helper text. | |
select | Select | The component that renders the select. |
Source code
If you did not find the information in this page, consider having a look at theimplementation of the component for more detail.