Skip to content

TextField API

API reference docs for the React TextField component. Learn about the props, CSS, and other APIs of this exported module.

Component demos

Import

import TextField from '@mui/material/TextField';
// or
import { TextField } from '@mui/material';
Learn about the difference by reading this guide on minimizing bundle size.

The TextField 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 abstraction on top of the following components:

If you wish to alter the props applied to the input element, you can do so as follows:

const inputProps = {
  step: 300,
};

return <TextField id="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

Props of the FormControl component are also available.

autoComplete

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 it following the specification.

Type:string


autoFocus

If true, the input element is focused during the first mount.

Type:bool

Default:false


classes

Override or extend the styles applied to the component.

See CSS API below for more details.

Type:object


color

The color of the component. It supports both default and custom theme colors, which can be added as shown in the palette customization guide.

Type:'primary'
| 'secondary'
| 'error'
| 'info'
| 'success'
| 'warning'
| string

Default:'primary'


defaultValue

The default value. Use when the component is not controlled.

Type:any


disabled

If true, the component is disabled.

Type:bool

Default:false


error

If true, the label is displayed in an error state.

Type:bool

Default:false


FormHelperTextProps

Props applied to the FormHelperText element.

Type:object


fullWidth

If true, the input will take up the full width of its container.

Type:bool

Default:false


helperText

The helper text content.

Type:node


id

The id of the input element. Use this prop to make label and helperText accessible for screen readers.

Type:string


InputLabelProps

Props applied to the InputLabel element. Pointer events like onClick are enabled if and only if shrink is true.

Type:object


inputProps

Attributes applied to the input element.

Type:object


InputProps

Props applied to the Input element. It will be a FilledInput, OutlinedInput or Input component depending on the variant prop value.

Type:object


inputRef

Pass a ref to the input element.

Type:ref


label

The label content.

Type:node


margin

If dense or normal, will adjust vertical spacing of this and contained components.

Type:'dense'
| 'none'
| 'normal'

Default:'none'


maxRows

Maximum number of rows to display when multiline option is set to true.

Type:number
| string


minRows

Minimum number of rows to display when multiline option is set to true.

Type:number
| string


multiline

If true, a textarea element is rendered instead of an input.

Type:bool

Default:false


name

Name attribute of the input element.

Type:string


onChange

Callback fired when the value is changed.

Type:func

Signature:
function(event: object) => void
  • event The event source of the callback. You can pull out the new value by accessing event.target.value (string).

placeholder

The short hint displayed in the input before the user enters a value.

Type:string


required

If true, the label is displayed as required and the input element is required.

Type:bool

Default:false


rows

Number of rows to display when multiline option is set to true.

Type:number
| string


select

Render a Select element while passing the Input element to Select as input parameter. If this option is set you must pass the options of the select as children.

Type:bool

Default:false


SelectProps

Props applied to the Select element.

Type:object


size

The size of the component.

Type:'medium'
| 'small'
| string


sx

The system prop that allows defining system overrides as well as additional CSS styles.

See the `sx` page for more details.

Type:Array<func
| object
| bool>
| func
| object


type

Type of the input element. It should be a valid HTML5 input type.

Type:string


value

The value of the input element, required for a controlled component.

Type:any


variant

The variant to use.

Type:'filled'
| 'outlined'
| 'standard'

Default:'outlined'


The ref is forwarded to the root element.

Inheritance

While not explicitly documented above, the props of the FormControl component are also available in TextField. You can take advantage of this to target nested components.


Theme default props

You can use MuiTextField to change the default props of this component with the theme.


CSS classes

These class names are useful for styling with CSS. They are applied to the component's slots when specific states are triggered.

.MuiTextField-root

Styles applied to the root element.

Rule name:root



You can override the style of the component using one of these customization options:

Edit this page

Was this page helpful?


TabScrollButtonTimeline

Blog

Store