datepickers
A datepicker is a text input to capture a date. You can select a single date, date range or date and time.
June
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
|---|---|---|---|---|---|---|
| 31 | 1 | 2 | 3 | 4 | 5 | 6 |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 1 | 2 | 3 | 4 |
About Datepickers
Implementation
The datepicker is a form element, containing a label and text input, and a dropdown menu, containing a grid-based calendar and filters. The 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 datepicker has the following markup requirements:
Desktop:
- Add
.slds-is-opento the element with.slds-dropdown-triggerto invoke the dropdown that contains the datepicker. - The
.slds-is-selectedmodifier class is required on thetdelement that has the selected day. - The
.slds-is-todaymodifier class is required on thetdelement that is the current day. - The
.slds-has-multi-selectionmodifier class is required on thetrelement that contains multiple days selected in the same week. - The
.slds-has-multi-row-selectionmodifier class is required on anytrelement that contains multiple days selected in the multiple weeks. - The
.slds-is-selected-multimodifier class is required on thetdelement that contains a selected day within a range.
Mobile:
- When on mobile, we want to leverage the native date picker by changing the
inputtype fromtexttodate - The
input type="date"will create an input field allowing a date and time to be easily entered — this includes year, month, day. - When switching
input type="text"toinput type="date"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
inputthat we just addedtype="date"to, please removearia-controls,aria-autocomplete, androle="textbox".
- On the element with the class
Accessibility
Markup
Dialog:
- Should act as a focus trap so the user only cycles through the datepicker
dialogwhen the datepicker is open
Grid:
- Table must be labelled with
role="grid"and be appropriately labelled witharia-labelledby - Use
aria-multiselectable="true"to allow for selection of multiple days - Should act as a single focus stop
Gridcell:
- All dates should have
role="gridcell"andaria-selected="false"on thegridcellby default - If a date is selected,
aria-selectedshould be set totrueon the correspondinggridcell aria-currentis used to indicate which day is today and should be set toaria-current="date"
Opening the Datepicker:
- Mouse user: open the datepicker when a mouse user clicks on the input
- Keyboard user: only open the datepicker when a keyboard user presses
enterorspaceon the datepicker button- Do not open the datepicker when user focus is on the input
Keyboard Interactions
- When the datepicker opens, place user focus on either the currently selected date in the grid or if no date is selected the current day
leftandrightarrow keys to navigate rowupanddownarrow keys to navigate between weeks on the same dayhomeandendkeys to jump to beginning or end of current rowpagedownandpageupto navigate between monthsalt + pagedownandalt + pageupto navigate between yearsenterto select date and close datepickerescto close datepicker without choosing a date
Base
June
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
|---|---|---|---|---|---|---|
| 31 | 1 | 2 | 3 | 4 | 5 | 6 |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 1 | 2 | 3 | 4 |
<div style="height:25rem">
<div class="slds-form-element slds-dropdown-trigger slds-dropdown-trigger_click slds-is-open">
<label class="slds-form-element__label" for="date-input-id-default">Date</label>States
Date Selected
June
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
|---|---|---|---|---|---|---|
| 31 | 1 | 2 | 3 | 4 | 5 | 6 |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 1 | 2 | 3 | 4 |
<div style="height:25rem">
<div class="slds-form-element slds-dropdown-trigger slds-dropdown-trigger_click slds-is-open">
<label class="slds-form-element__label" for="date-input-id-day_selected">Date</label>Date Picker Has Error
June
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
|---|---|---|---|---|---|---|
| 31 | 1 | 2 | 3 | 4 | 5 | 6 |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 1 | 2 | 3 | 4 |
<div style="height:25rem">
<div class="slds-form-element slds-has-error slds-dropdown-trigger slds-dropdown-trigger_click slds-is-open">
<label class="slds-form-element__label" for="date-input-id-error">Date</label>Range
<div style="height:25rem">
<div class="slds-form slds-form_compound">
<fieldset class="slds-form-element">States
Start Date Selected
<div style="height:25rem">
<div class="slds-form slds-form_compound">
<fieldset class="slds-form-element">End date selected (Same week)
<div style="height:25rem">
<div class="slds-form slds-form_compound">
<fieldset class="slds-form-element">End date selected (Different week)
<div style="height:25rem">
<div class="slds-form slds-form_compound">
<fieldset class="slds-form-element">Today - In selected range
<div style="height:25rem">
<div class="slds-form slds-form_compound">
<fieldset class="slds-form-element">Current And Adjacent Month In Selected Range
<div style="height:25rem">
<div class="slds-form slds-form_compound">
<fieldset class="slds-form-element">