Description
Issue description
Text fields allow users to enter text into a UI. They typically appear in forms and dialogs.
Import
import TextField from '@mnui/material/TextField;
// or
import { TextField } from '@mnui/material';
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.
Components
TextField is composed of smaller components ( FormControl, Input, FilledInput, OutlinedInput, and FormHelperText ) that you can leverage directly to significantly customize your form inputs.
You might also have noticed that some native HTML input properties are missing from the TextField component. This is on purpose. The component takes care of the most used properties. Then, it's up to the user to use the underlying component shown in the following demo. Still, you can use inputProps (and InputProps, InputLabelProps properties) if you want to avoid some boilerplate.
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 native componenta and FormControl 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 it following the specification. | |
autoFocus | bool | false | If true , the input element is focused during the first mount. |
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. |
defaultValue | any | The default value. Use when the component is not controlled. | |
disabled | bool | false | If true , the component is disabled. |
error | bool | false | If true , the label is displayed in an error state. |
FormHelperTextProps | object | Props applied to the FormHelperText element. |
|
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 input element. Use this prop to make label and helperText accessible for screen readers. |
|
InputLabelProps | object | Props applied to the InputLabel element. Pointer events like onPress are enabled if and only if shrink is true . |
|
InputProps | object | Props applied to the Input element. It will be a FilledInput , OutlinedInput or Input component depending on the variant prop value. |
|
inputRef | ref | Pass a ref to the input element. |
|
label | node | The label content. | |
margin | 'dense', 'none', 'normal' |
'none' | If dense or normal , 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 , a textarea element is rendered instead of an input. |
onChange | func | Callback fired when the value is changed. Signature: function({ nativeEvent: { eventCount, target, text} }) => void event: 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 input before the user enters a value. |
|
required | bool | false | If true , the label is displayed as required and the input element is required. |
rows | number, | Number of rows to display when multiline option is set to true. only applied to text type. limitation | |
size | 'medium', 'small', string |
The size of the component. | |
sx | Array<func, object, bool>, func, object |
The system prop that allows defining system overrides as well as additional CSS styles. See the `sx` epic for more details. | |
type | 'number', 'text', 'password' |
Type of the textInput element.. |
|
value | any | The value of the input element, required for a controlled component. |
|
variant | 'filled', 'outlined', 'standard' |
'outlined' | The variant to use. |
The ref is forwarded to the root element.