Skip to content

SingleInputDateTimeRangeField API

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

Demos

Import

import { SingleInputDateTimeRangeField } from '@mui/x-date-pickers-pro/SingleInputDateTimeRangeField';
// or
import { SingleInputDateTimeRangeField } 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.

NameTypeDefaultDescription
ampmboolutils.is12HourCycleInCurrentLocale()

12h/24h view for hour selection clock.

autoFocusboolfalse

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

clearableboolfalse

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

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.

dateSeparatorstring"–"

String displayed between the start and the end dates.

defaultValueArray<object>-

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

disabledboolfalse

If true, the component is disabled. When disabled, the value cannot be changed and no interaction is possible.

disableFutureboolfalse

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

disableIgnoringDatePartForTimeValidationboolfalse

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

disablePastboolfalse

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

focusedbool-

If true, the component is displayed in focused state.

formatstring-

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

formatDensity'dense'
| 'spacious'
"dense"

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

FormHelperTextPropsobject-

Props applied to the FormHelperText element.

fullWidthboolfalse

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

helperTextnode-

The helper text content.

hiddenLabelboolfalse

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.

idstring-

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

InputLabelPropsobject-

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

inputPropsobject-

Attributes applied to the input element.

InputPropsobject-

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

inputRefref-

Pass a ref to the input element.

labelnode-

The label content.

margin'dense'
| 'none'
| 'normal'
'none'

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

maxDateobject2099-12-31

Maximal selectable date.

maxDateTimeobject-

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

maxTimeobject-

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

minDateobject1900-01-01

Minimal selectable date.

minDateTimeobject-

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

minTimeobject-

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

minutesStepnumber1

Step over minutes.

namestring-

Name attribute of the input element.

onChangefunc-

Callback fired when the value changes.

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

Callback fired when the clear button is clicked.

onErrorfunc-

Callback fired when the error associated with the current value changes. When a validation error is detected, the error parameter contains a non-null value. This can be used to render an appropriate form error.

Signature:function(error: TError, value: TValue) => void
  • error The reason why the current value is not valid.
  • value The value associated with the error.
onSelectedSectionsChangefunc-

Callback fired when the selected sections change.

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

If true, the component is read-only. When read-only, the value cannot be changed but the user can interact with the interface.

referenceDateobjectThe 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 value and defaultValue are empty. For example, on time fields it will be used to determine the date to set.

requiredboolfalse

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

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 FieldSectionType is provided, the first section with that name will be selected. 3. If "all" is provided, all the sections will be selected. 4. If null is provided, no section will be selected. If not provided, the selected sections will be handled internally.

shouldDisableDatefunc-

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

Signature:function(day: PickerValidDate, position: string) => boolean
  • day The date to test.
  • position The date to test, 'start' or 'end'.

Returns: Returns true if the date should be disabled.

shouldDisableTimefunc-

Disable specific time.

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

Returns: If true the time will be disabled.

shouldRespectLeadingZerosboolfalse

If true, the format will respect the leading zeroes (for example on dayjs, the format M/D/YYYY will render 8/16/2018) If false, the format will always add leading zeroes (for example 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 (for example "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.

size'medium'
| 'small'
-

The size of the component.

slotPropsobject{}

The props used for each component slot.

slotsobject{}

Overridable component slots.

See Slots API below for more details.

sxArray<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.

timezonestringThe 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.

unstableFieldReffunc
| object
-

The ref object used to imperatively interact with the field.

valueArray<object>-

The selected value. Used when the component is controlled.

variant'filled'
| 'outlined'
| 'standard'
'outlined'

The variant to use.

The ref is forwarded to the root element.

Theme default props

You can use MuiSingleInputDateTimeRangeField 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.

Class nameRule nameDescription
.MuiSingleInputDateTimeRangeField-rootrootStyles applied to the root element.

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

Source code

If you did not find the information in this page, consider having a look at the implementation of the component for more detail.