Skip to content

DateTimeField API

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

Component demos

Import

import { DateTimeField } from '@mui/x-date-pickers/DateTimeField';
// or
import { DateTimeField } from '@mui/x-date-pickers';
// or
import { DateTimeField } from '@mui/x-date-pickers-pro';
Learn about the difference by reading this guide on minimizing bundle size.

Props

Props of the native component are also available.

ampm

12h/24h view for hour selection clock.

Type:bool

Default:`utils.is12HourCycleInCurrentLocale()`


autoFocus

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

Type:bool

Default:false


clearable

If true, a clear button will be shown in the field allowing value clearing.

Type:bool

Default:false


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:'error'
| 'info'
| 'primary'
| 'secondary'
| 'success'
| 'warning'

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


disableFuture

If true, disable values after the current date for date components, time for time components and both for date time components.

Type:bool

Default:false


disableIgnoringDatePartForTimeValidation

Do not ignore date part when validating min/max time.

Type:bool

Default:false


disablePast

If true, disable values before the current date for date components, time for time components and both for date time components.

Type:bool

Default:false


focused

If true, the component is displayed in focused state.

Type:bool


format

Format of the date when rendered in the input(s).

Type:string


formatDensity

Density of the format when rendered in the input. Setting formatDensity to "spacious" will add a space before and after each /, - and . character.

Type:'dense'
| 'spacious'

Default:"dense"


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


hiddenLabel

If true, the label is hidden. This is used to increase density for a FilledInput. Be sure to add aria-label to the input element.

Type:bool

Default:false


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'


maxDate

Maximal selectable date.

Type:any


maxDateTime

Maximal selectable moment of time with binding to date, to set max time in each day use maxTime.

Type:any


maxTime

Maximal selectable time. The date part of the object will be ignored unless props.disableIgnoringDatePartForTimeValidation === true.

Type:any


minDate

Minimal selectable date.

Type:any


minDateTime

Minimal selectable moment of time with binding to date, to set min time in each day use minTime.

Type:any


minTime

Minimal selectable time. The date part of the object will be ignored unless props.disableIgnoringDatePartForTimeValidation === true.

Type:any


minutesStep

Step over minutes.

Type:number

Default:1


name

Name attribute of the input element.

Type:string


onChange

Callback fired when the value changes.

Type:func

Signature:
function(value: TValue, context: FieldChangeHandlerContext) => void
  • value The new value.
  • context The context containing the validation result of the current value.

onClear

Callback fired when the clear button is clicked.

Type:func


onError

Callback fired when the error associated to the current value changes.

Type:func

Signature:
function(error: TError, value: TValue) => void
  • error The new error.
  • value The value associated to the error.

onSelectedSectionsChange

Callback fired when the selected sections change.

Type:func

Signature:
function(newValue: FieldSelectedSections) => void
  • newValue The new selected sections.

readOnly

It prevents the user from changing the value of the field (not from interacting with the field).

Type:bool

Default:false


referenceDate

The date used to generate a part of the new value that is not present in the format when both value and defaultValue are empty. For example, on time fields it will be used to determine the date to set.

Type:any

Default:The closest valid date using the validation props, except callbacks such as `shouldDisableDate`. Value is rounded to the most granular section used.


required

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

Type:bool

Default:false


selectedSections

The currently selected sections. This prop accept four formats: 1. If a number is provided, the section at this index will be selected. 2. If an object with a startIndex and endIndex properties are provided, the sections between those two indexes will be selected. 3. If a string of type FieldSectionType is provided, the first section with that name will be selected. 4. If null is provided, no section will be selected If not provided, the selected sections will be handled internally.

Type:'all'
| 'day'
| 'empty'
| 'hours'
| 'meridiem'
| 'minutes'
| 'month'
| 'seconds'
| 'weekDay'
| 'year'
| number
| { endIndex: number, startIndex: number }


shouldDisableDate

Disable specific date.
Warning: This function can be called multiple times (e.g. when rendering date calendar, checking if focus can be moved to a certain date, etc.). Expensive computations can impact performance.

Type:func

Signature:
function(day: TDate) => boolean
  • day The date to test.

Returns: If true the date will be disabled.


shouldDisableMonth

Disable specific month.

Type:func

Signature:
function(month: TDate) => boolean
  • month The month to test.

Returns: If true, the month will be disabled.


shouldDisableTime

Disable specific time.

Type:func

Signature:
function(value: TDate, view: TimeView) => boolean
  • value The value to check.
  • view The clock type of the timeValue.

Returns: If true the time will be disabled.


shouldDisableYear

Disable specific year.

Type:func

Signature:
function(year: TDate) => boolean
  • year The year to test.

Returns: If true, the year will be disabled.


shouldRespectLeadingZeros

If true, the format will respect the leading zeroes (e.g: on dayjs, the format M/D/YYYY will render 8/16/2018) If false, the format will always add leading zeroes (e.g: on dayjs, the format M/D/YYYY will render 08/16/2018)
Warning n°1: Luxon is not able to respect the leading zeroes when using macro tokens (e.g: "DD"), so shouldRespectLeadingZeros={true} might lead to inconsistencies when using AdapterLuxon.
Warning n°2: When shouldRespectLeadingZeros={true}, the field will add an invisible character on the sections containing a single digit to make sure onChange is fired. If you need to get the clean value from the input, you can remove this character using input.value.replace(/\u200e/g, '').
Warning n°3: When used in strict mode, dayjs and moment require to respect the leading zeros. This mean that when using shouldRespectLeadingZeros={false}, if you retrieve the value directly from the input (not listening to onChange) and your format contains tokens without leading zeros, the value will not be parsed by your library.

Type:bool

Default:`false`


size

The size of the component.

Type:'medium'
| 'small'


slotProps

The props used for each component slot.

Type:object

Default:{}


slots

Overridable component slots.

Type:object

Default:{}


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


timezone

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.

Type:string

Default:The timezone of the `value` or `defaultValue` prop is defined, 'default' otherwise.


unstableFieldRef

The ref object used to imperatively interact with the field.

Type:func
| object


value

The selected value. Used when the component is controlled.

Type:any


variant

The variant to use.

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

Default:'outlined'


The ref is forwarded to the root element.

CSS

The following class names are useful for styling with CSS (the state classes are marked).
To learn more, visit the component customization page.

.MuiDateTimeField-root

Styles applied to the root element.

Rule name:root



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

Slots

clearButton

Button to clear the value.

Default: IconButton


clearIcon

Icon to display inside the clear button.

Default: ClearIcon


textField

Form control with an input to render the value. Receives the same props as @mui/material/TextField.

Default: TextField from '@mui/material'