datetime-picker
A datetime picker is used to select a day and a time.
About datetime picker
Implementation
The datetime is two form elements, each containing a label and text input, and a dropdown menu, containing a grid-based calendar and filters. The date form element acts as a trigger for the dropdown.
Placement of inline form elements inside a data table cell is not supported. Instead, use a button to invoke a popover, which does support form elements.
The datetime picker has the following markup requirements:
Desktop
- Add
.slds-is-open
to the element with.slds-dropdown-trigger
to invoke the dropdown that contains the datepicker and the list of time options. - On the timepicker, the
.slds-has-focus
modifier class is required on the.slds-listbox__option
element that has focus. - On the timepicker, the
.slds-is-selected
modifier class is required on the.slds-listbox__option
element that has been selected. - On the datepicker, the
.slds-is-selected
modifier class is required on thetd
element that has the selected day. - On the datepicker, the
.slds-is-today
modifier class is required on thetd
element that is the current day.
Mobile
- When on mobile, we want to leverage the native datetime picker by changing the
input
type fromtext
todatetime-local
- The
input type="datetime-local"
will create an input field allowing a date and time to be easily entered — this includes year, month, day, hours, and minutes. - When switching
input type="text"
toinput type="datetime-local"
for mobile, we need to remove the ARIA attributes. The native rendering doesn't require these.- On the element with the class
slds-combobox
, please removerole="combobox"
,aria-expanded
, andaria-haspopup
. - On the
input
that we just addedtype="datetime-local"
to, please removearia-controls
,aria-autocomplete
, androle="textbox"
.
- On the element with the class
Base
<div class="slds-form slds-form_compound">
<fieldset class="slds-form-element">
<legend class="slds-form-element__label slds-form-element__legend">Date and Time</legend>
States
Date selection
<div class="slds-form slds-form_compound">
<fieldset class="slds-form-element">
<legend class="slds-form-element__label slds-form-element__legend">Date and Time</legend>
Time selection
<div class="slds-form slds-form_compound">
<fieldset class="slds-form-element">
<legend class="slds-form-element__label slds-form-element__legend">Date and Time</legend>