MaskedDateInput
Masked date input with individual fields for day, month and year
Source
Package
Usage
MaskedDateInput is similar to TimePicker but for dates.
It renders masked fields for day, month and year with an optional calendar dropdown:
MaskedDateInput with uncontrolled forms
Set name to submit a complete date, including the time if withTime is set. An incomplete or empty date submits an empty string:
Controlled
The value is a string in YYYY-MM-DD format, or YYYY-MM-DD HH:mm:ss when withTime is set.
null represents no value. onChange is called when all fields are filled or when all fields are cleared:
null
With time
Set the withTime prop to display hours and minutes fields in addition to date fields:
With seconds
Set the withSeconds prop to display the seconds field, withTime must also be set:
12-hour format
Set format="12h" to use 12-hour time format with an am/pm selector:
Change am/pm labels
Use the amPmLabels prop to customize am/pm labels:
Date separator
Use the dateSeparator prop to change the separator displayed between date fields:
Time separator
Use the timeSeparator prop to change the separator displayed between time fields:
Fields order
Use the fieldsOrder prop to change the order of day, month and year fields:
Min and max dates
Set minDate and maxDate to restrict the date range.
An out-of-range date is clamped to the nearest valid date when the input loses focus:
Allow deselect
Set the allowDeselect prop to allow clearing the value by clicking the selected date in the
calendar dropdown:
Without dropdown
Set withDropdown={false} to disable the calendar dropdown:
Dropdown position
Use popoverProps to pass props down to the underlying Popover component, for example to display the dropdown above the input.
The dropdown scrolls when it does not fit in the viewport, pass middlewares: { size: false } to disable this behavior:
Hours/minutes/seconds step
Use hoursStep, minutesStep and secondsStep props to change the arrow keys step of time fields:
Paste events
By default, MaskedDateInput handles pasted ISO dates and date-times.
Use pasteSplit to parse other formats:
Try pasting a date in DD.MM.YYYY format. For example, try pasting 15.06.2000
Controlling with useMaskedDateInput
MaskedDateInput component supports the controller pattern. Use the useMaskedDateInput hook to manage MaskedDateInput state.
When the controller prop is set, the value, time, format and date limit props of the component are ignored, pass them to useMaskedDateInput instead:
Value: null, day: null, month: null, year: null
useMaskedDateInput accepts the state options that MaskedDateInput accepts as props, and returns actions and queries:
Usage with forms
A controller and form.getInputProps() cannot be spread on the same component: the controller ignores value and onChange.
Instead, wrap MaskedDateInput in a component that owns the controller and bind the form to that component, see the controllers guide.
A partially entered date is null for the form, use controller.hasValue() and the field queries to report it with a specific message:
Clearable
Set the clearable prop to display a clear button in the right section of the input:
Clear section mode
The clearSectionMode prop determines how the clear button and rightSection are rendered:
'both'(default) – render both the clear button andrightSection'rightSection'– render only the user-suppliedrightSection, ignore clear button'clear'– render only the clear button, ignorerightSection
Disabled
Read only
Input props
MaskedDateInput component supports Input and Input.Wrapper component features and all div element props. The MaskedDateInput documentation does not include all features supported by the component – see the Input documentation to learn about all available features.
Input description
Get refs
Every field has a ref prop, for example dayRef or hoursRef, to get the ref of its input:
onFocus and onBlur
onFocus is called when one of the inputs receives focus and onBlur is called when focus
leaves all inputs:
Accessibility
Each field has an English aria-label by default. Use the corresponding props to translate the labels.
If clearable is set, also label the clear button:
Keyboard interactions: