TextField API
Importação
import TextField from '@mui/material/TextField';
// ou
import { TextField } from '@mui/material';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
Nome do componente
The nameMuiTextField can be used when providing default props or style overrides in the theme.Propriedades
Propriedades do componente FormControl também estão disponíveis.
| Nome | Tipo | Padrão | Descrição | 
|---|---|---|---|
| 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 it following the specification. | |
| autoFocus | bool | false | If  true, theinputelement is focused during the first mount. | 
| classes | object | Sobrescreve ou extende os estilos aplicados para o componente. Veja a API CSS abaixo para maiores detalhes. | |
| 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 the palette customization guide. | 
| defaultValue | any | The default input value. Use when the component is not controlled. | |
| disabled | bool | false | Se  true, o componente está desabilitado. | 
| error | bool | false | If  true, the label should be displayed in an error state. | 
| FormHelperTextProps | object | Props applied to the  FormHelperTextelement. | |
| fullWidth | bool | false | If  true, the input will take up the full width of its container. | 
| helperText | node | The helper text content. | |
| id | string | The id of the  inputelement. Use this prop to makelabelandhelperTextaccessible for screen readers. | |
| InputLabelProps | object | Props applied to the  InputLabelelement. Pointer events likeonClickare enabled if and only ifshrinkistrue. | |
| inputProps | object | Attributes applied to the  inputelement. | |
| InputProps | object | Props applied to the Input element. It will be a  FilledInput,OutlinedInputorInputcomponent depending on thevariantprop value. | |
| inputRef | ref | Pass a ref to the  inputelement. | |
| label | node | The label content. | |
| margin | 'dense' | 'none' | 'normal' | 'none' | If  denseornormal, will adjust vertical spacing of this and contained components. | 
| 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  true, atextareaelement is rendered.instead of an input. | 
| name | string | Name attribute of the  inputelement. | |
| onChange | func | Callback fired when the value is changed. Signature: function(event: object) => voidevent: The event source of the callback. You can pull out the new value by accessing event.target.value(string). | |
| placeholder | string | The short hint displayed in the  inputbefore the user enters a value. | |
| required | bool | false | If  true, the label is displayed as required and theinputelement is required. | 
| rows | number | string | Number of rows to display when multiline option is set to true. | |
| select | bool | false | Render a  Selectelement while passing the Input element toSelectasinputparameter. If this option is set you must pass the options of the select as children. | 
| SelectProps | object | Props applied to the  Selectelement. | |
| size | 'medium' | 'small' | string | The size of the autocomplete. | |
| 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  inputelement. It should be a valid HTML5 input type. | |
| value | any | The value of the  inputelement, required for a controlled component. | |
| variant | 'filled' | 'outlined' | 'standard' | 'outlined' | A variante a usar. | 
O
ref é encaminhado para o elemento raiz.Herança
While not explicitly documented above, the props of the FormControl component are also available on TextField. You can take advantage of this to target nested components.CSS
| Nome da regra | Classe global | Descrição | 
|---|---|---|
| root | .MuiTextField-root | Estilos aplicados ao elemento raiz. | 
Você pode sobrescrever o estilo do componente usando uma dessas opções de customização:
- With a global class name.
- With a rule name as part of the component's styleOverridesproperty in a custom theme.