DatePicker props
DateTimePicker supports most of the DatePicker props.
Read through the DatePicker documentation to learn about all component features that are not listed on this page.
DateTimePicker with uncontrolled forms
Set name to submit the selected date and time as YYYY-MM-DD HH:mm:ss, regardless of the display format:
Usage
Range
Set type="range" to allow selecting a date and time range. In range mode,
two time inputs are rendered for start and end times, and a range summary is displayed below:
With seconds
Presets
Use the presets prop to add custom date presets. Presets are displayed next to the calendar:
TimePicker props
You can pass props down to the underlying TimePicker component
with the timePickerProps prop. Example of enabling dropdown and setting 12h format
for the time picker:
Controlling with useDateTimePicker
DateTimePicker component supports the controller pattern. Use the useDateTimePicker hook to manage DateTimePicker state:
Dropdown closed, displayed month: none
useDateTimePicker has the actions and queries of
useDatePickerInput – the dropdown
actions together with the navigation actions of useCalendar –
and the time actions of useInlineDateTimePicker:
The controller does not own the selected value – keep using value/onChange (or your form
library) for it. It owns what the value cannot express: the time entered before a date is picked
and the end time of an incomplete range. setTime updates the time of the value when it has a date.
When the dropdown is closed, the time set with setTime is shown and applied to the value the next
time it opens. When the controller prop is set, the date, defaultDate, onDateChange, level,
defaultLevel, onLevelChange and defaultTimeValue props are ignored – pass them to
useDateTimePicker instead.
Every time the dropdown opens, it starts fresh: the displayed date is reset to the selected value
(or to defaultDate when there is no value), the level is reset to defaultLevel, and the time
inputs show the time of the value, discarding an incomplete time or a time typed before a date was
picked. To open on a different level, date or time, call setLevel, setDate or setTime right
after openDropdown, as the demo above does. A controlled date, level or time is not reset.
openDropdown does nothing while the input is disabled or readOnly. closeDropdown works the
same way as when the user dismisses the dropdown: with type="range", a range with only the first
date picked is cleared, the value is clamped to minDate/maxDate and onDropdownClose is called.
The time inputs are driven through the DateTimePicker controller, so timePickerProps does not
accept a controller. When the controller prop is set, popoverProps.opened and
popoverProps.onChange are ignored – pass dropdownOpened and onDropdownOpenedChange to
useDateTimePicker instead. Without a controller, popoverProps={{ opened, onChange }} controls the
dropdown in every dropdown type (popover, modal and drawer).
The controller is typed as DateTimePickerController and its options as
DateTimePickerControllerOptions, both exported from @mantine/dates.
Value format
Use the valueFormat prop to change the dayjs format of the value label:
valueFormat also accepts a function that receives the value as a YYYY-MM-DD HH:mm:ss string
and returns a custom formatted value. Use it when the formatting logic cannot be expressed with a
dayjs format string:
Disabled state
Input props
DateTimePicker component supports Input and Input.Wrapper component features and all button element props. The DateTimePicker documentation does not include all features supported by the component – see the Input documentation to learn about all available features.
Input description
Clearable
Set the clearable prop to display a clear button in the right section. Note that if you set the rightSection
prop, the clear button will not be displayed.
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
Dropdown type
The dropdown opens in a bottom Drawer below theme.breakpoints.sm and in a
Popover above. Set dropdownType to 'popover', 'modal', 'drawer' or an object
with breakpoints:
Object keys can be theme.breakpoints keys or custom values in px, for example,
{ base: 'drawer', 600: 'popover' }. Use popoverProps, modalProps and drawerProps to pass props
down to the underlying component. If the viewport crosses a breakpoint while the dropdown is open,
the dropdown switches to the other type and a selection that was not applied yet is discarded.
Submit button
In drawer and modal dropdowns, the value is applied only when the submit button is pressed, and
closing the dropdown discards the selection. Set applyOnSubmit={false} to apply the value on selection:
- The submit button is rendered in every dropdown type
- The label is
Saveby default – change it with thesubmitButtonLabelprop or thesubmitButtonLabelsetting of DatesProvider submitButtonPropsare passed down to the Button- With
type="range", the button is disabled until both dates are selected
Mobile time input
In the drawer dropdown, time is entered with a native <input type="time" /> (TimeInput)
instead of TimePicker. With withSeconds (as a prop or in timePickerProps),
TimePicker is used in all dropdown types. disabled, readOnly, aria-label,
aria-describedby, id, name, className and style from timePickerProps (and from
endTimePickerProps for the end time input) are applied to the native input as well.
Native level select
Get element ref
Accessibility
If DateTimePicker is used without the label prop, it will not be announced properly by screen readers:
Set aria-label to make the input accessible. In this case the label will not be visible, but screen readers will announce it:
If the label prop is set, the input will be accessible and it is not required to set aria-label: