MultiInputDateRangeField API
Demos
For examples and details on the usage of this React component, visit the component demo pages:
Import
import MultiInputDateRangeField from '/packages/x-date-pickers-pro/src/MultiInputDateRangeField';
// or
import { MultiInputDateRangeField } from '/packages/x-date-pickers-pro/src';
Props
Defines the flex-direction
style property. It is applied for all screen sizes.
Type:
'column-reverse' | 'column' | 'row-reverse' | 'row' | Array<'column-reverse' | 'column' | 'row-reverse' | 'row'> | object
Default:
'column'
If true
, disable values after the current date for date components, time for time components and both for date time components.
Type:
bool
If true
, disable values before the current date for date components, time for time components and both for date time components.
Type:
bool
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"
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.
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.
Callback fired when the selected sections change.
Type:
func
Signature:
function(newValue: FieldSelectedSections) => void
newValue
The new selected sections.
It prevents the user from changing the value of the field (not from interacting with the field).
Type:
bool
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.
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' | 'hours' | 'meridiem' | 'minutes' | 'month' | 'seconds' | 'weekDay' | 'year' | number | { endIndex: number, startIndex: number }
Disable specific date.
Type:
func
Signature:
function(day: TDate, 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.
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`
Defines the space between immediate children.
Type:
Array<number | string> | number | object | string
Default:
0
The system prop, which allows defining system overrides as well as additional CSS styles.
See the `sx` page for more details.
Type:
Array<func | object | bool> | func | object
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 documention for more details.
Type:
string
Default:
The timezone of the `value` or `defaultValue` prop is defined, 'default' otherwise.
If true
, the CSS flexbox gap
is used instead of applying margin
to children.
While CSS gap
removes the known limitations, it is not fully supported in some browsers. We recommend checking https://caniuse.com/?search=flex%20gap before using this flag.
To enable this flag globally, follow the theme's default props configuration.
Type:
bool
Slots
Default: MultiInputDateRangeFieldSeparator
Description: Element rendered between the two inputs.
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.