DateField API
API reference docs for the React DateField component. Learn about the props, CSS, and other APIs of this exported module.
Component demos
Import
import { DateField } from '@mui/x-date-pickers/DateField';
// or
import { DateField } from '@mui/x-date-pickers';
// or
import { DateField } from '@mui/x-date-pickers-pro';
Props of the native component are also available.
Name | Type | Default | Description |
---|---|---|---|
autoFocus | bool | false | If |
clearable | bool | false | If |
color | 'error' | 'info' | 'primary' | 'secondary' | 'success' | 'warning' | '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 | object | - | The default value. Use when the component is not controlled. |
disabled | bool | false | If |
disableFuture | bool | false | If |
disablePast | bool | false | If |
focused | bool | - | If |
format | string | - | Format of the date when rendered in the input(s). |
formatDensity | 'dense' | 'spacious' | "dense" | Density of the format when rendered in the input. Setting |
FormHelperTextProps | object | - | Props applied to the |
fullWidth | bool | false | If |
helperText | node | - | The helper text content. |
id | string | - | The id of the |
InputLabelProps | object | - | Props applied to the |
inputProps | object | - | Attributes applied to the |
InputProps | object | - | Props applied to the Input element. It will be a |
inputRef | ref | - | Pass a ref to the |
label | node | - | The label content. |
margin | 'dense' | 'none' | 'normal' | 'none' | If |
maxDate | object | - | Maximal selectable date. |
minDate | object | - | Minimal selectable date. |
name | string | - | Name attribute of the |
onChange | func | - | Callback fired when the value changes. Signature: function(value: TValue, context: FieldChangeHandlerContext
|
onClear | func | - | Callback fired when the clear button is clicked. |
onError | func | - | Callback fired when the error associated to the current value changes. Signature: function(error: TError, value: TValue) => void
|
onSelectedSectionsChange | func | - | Callback fired when the selected sections change. Signature: function(newValue: FieldSelectedSections) => void
|
readOnly | bool | false | It prevents the user from changing the value of the field (not from interacting with the field). |
referenceDate | object | The closest valid date using the validation props, except callbacks such as `shouldDisableDate`. Value is rounded to the most granular section used. | The date used to generate a part of the new value that is not present in the format when both |
required | bool | false | If |
selectedSections | 'all' | 'day' | 'empty' | 'hours' | 'meridiem' | 'minutes' | 'month' | 'seconds' | 'weekDay' | 'year' | number | - | The currently selected sections. This prop accepts four formats: 1. If a number is provided, the section at this index will be selected. 2. If a string of type |
shouldDisableDate | func | - | Disable specific date. Signature: function(day: TDate) => boolean
Returns: If |
shouldDisableMonth | func | - | Disable specific month. Signature: function(month: TDate) => boolean
Returns: If |
shouldDisableYear | func | - | Disable specific year. Signature: function(year: TDate) => boolean
Returns: If |
shouldRespectLeadingZeros | bool | `false` | If |
size | 'medium' | 'small' | - | The size of the component. |
slotProps | object | {} | The props used for each component slot. |
slots | object | {} | Overridable component slots. See Slots API below for more details. |
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. |
timezone | string | The timezone of the `value` or `defaultValue` prop is defined, 'default' otherwise. | Choose which timezone to use for the value. Example: "default", "system", "UTC", "America/New_York". If you pass values from other timezones to some props, they will be converted to this timezone before being used. See the timezones documentation for more details. |
unstableFieldRef | func | object | - | The ref object used to imperatively interact with the field. |
value | object | - | The selected value. Used when the component is controlled. |
variant | 'filled' | 'outlined' | 'standard' | 'outlined' | The variant to use. |
ref
is forwarded to the root element.These class names are useful for styling with CSS. They are applied to the component's slots when specific states are triggered.
Class name | Rule name | Description |
---|---|---|
.MuiDateField-root | root | Styles applied to the root element. |
You can override the style of the component using one of these customization options:
- With a global class name.
- With a rule name as part of the component's
styleOverrides
property in a custom theme.