Datepickers
- HTML/CSS:Dev Ready
- Layout:Desktop Only
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-open
to the element with.slds-dropdown-trigger
to invoke the dropdown that contains the datepicker. - The
.slds-is-selected
modifier class is required on thetd
element that has the selected day. - The
.slds-is-today
modifier class is required on thetd
element that is the current day. - The
.slds-has-multi-selection
modifier class is required on thetr
element that contains multiple days selected in the same week. - The
.slds-has-multi-row-selection
modifier class is required on anytr
element that contains multiple days selected in the multiple weeks. - The
.slds-is-selected-multi
modifier class is required on thetd
element that contains a selected day within a range.
Mobile:
- When on mobile, we want to leverage the native date picker by changing the
input
type fromtext
todate
- 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
input
that 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
dialog
when 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 thegridcell
by default - If a date is selected,
aria-selected
should be set totrue
on the correspondinggridcell
aria-current
is used to indicate which day is today and should be set toaria-current="date"
aria-label
is used to provide the fullDD MM YYYY
text of the 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
enter
orspace
on 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
left
andright
arrow keys to navigate rowup
anddown
arrow keys to navigate between weeks on the same dayhome
andend
keys to jump to beginning or end of current rowpagedown
andpageup
to navigate between monthsalt + pagedown
andalt + pageup
to navigate between yearsenter
to select date and close datepickeresc
to 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 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>
<div class="slds-form-element__control slds-input-has-icon slds-input-has-icon_right">
<input type="text" id="date-input-id-default" placeholder=" " class="slds-input" />
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 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>
<div class="slds-form-element__control slds-input-has-icon slds-input-has-icon_right">
<input type="text" id="date-input-id-day_selected" placeholder=" " class="slds-input" value="06/24/2021" />
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 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>
<div class="slds-form-element__control slds-input-has-icon slds-input-has-icon_right">
<input type="text" id="date-input-id-error" placeholder=" " class="slds-input" />
Date Required#
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 class="slds-form-element slds-dropdown-trigger slds-dropdown-trigger_click slds-is-open">
<label class="slds-form-element__label" for="date-input-id-required">
<abbr class="slds-required" title="required">* </abbr>Date</label>
<div class="slds-form-element__control slds-input-has-icon slds-input-has-icon_right">
Date Required, 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 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-required">
<abbr class="slds-required" title="required">* </abbr>Date</label>
<div class="slds-form-element__control slds-input-has-icon slds-input-has-icon_right">
Range#
<div class="slds-form slds-form_compound">
<fieldset class="slds-form-element">
<legend class="slds-form-element__label slds-form-element__legend">Start and End Date</legend>
<div class="slds-form-element__control">
States#
Start Date Selected#
<div class="slds-form slds-form_compound">
<fieldset class="slds-form-element">
<legend class="slds-form-element__label slds-form-element__legend">Start and End Date</legend>
<div class="slds-form-element__control">
End date selected (Same week)#
<div class="slds-form slds-form_compound">
<fieldset class="slds-form-element">
<legend class="slds-form-element__label slds-form-element__legend">Start and End Date</legend>
<div class="slds-form-element__control">
End date selected (Different week)#
<div class="slds-form slds-form_compound">
<fieldset class="slds-form-element">
<legend class="slds-form-element__label slds-form-element__legend">Start and End Date</legend>
<div class="slds-form-element__control">
Today - In selected range#
<div class="slds-form slds-form_compound">
<fieldset class="slds-form-element">
<legend class="slds-form-element__label slds-form-element__legend">Start and End Date</legend>
<div class="slds-form-element__control">
Current And Adjacent Month In Selected Range#
<div class="slds-form slds-form_compound">
<fieldset class="slds-form-element">
<legend class="slds-form-element__label slds-form-element__legend">Start and End Date</legend>
<div class="slds-form-element__control">
Overview of CSS Classes#
- Selector
- The CSS class being referred to.
- Summary
- A description of what the class does.
- Support
- Whether the class name is dev-ready (meaning it's fully vetted and tested and safe to use) or prototype (which means it's not fully vetted yet).
- Restrict
- The selector that the class name is allowed to be used on.
- Variant
- The base level pattern for a component. A variant can be extended to create another variant of that component, for example, a stateful button is a derivative of the base button.
- Modifier
- A single class that can be added to an HTML element of a component to modify its output. Typically these will be colors, sizing and positioning.
Selector | .slds-datepicker |
---|---|
Summary | Initiates a datepicker component |
Support | dev-ready |
Restrict | div |
Variant | True |
Selector | .slds-disabled-text Deprecated |
---|---|
Summary | |
Restrict | .slds-datepicker td |
Selector | .slds-day |
---|---|
Summary | Style for calendar days |
Restrict | .slds-datepicker td span |
Selector | .slds-is-today |
---|---|
Summary | Indicates today |
Restrict | .slds-datepicker td |
Selector | .slds-is-selected |
---|---|
Summary | Indicates selected days |
Restrict | .slds-datepicker td |
Selector | .slds-datepicker__filter |
---|---|
Summary | Aligns filter items horizontally |
Restrict | .slds-datepicker div |
Selector | .slds-datepicker__filter_month |
---|---|
Summary | Spaces out month filter |
Restrict | .slds-datepicker div |
Selector | .slds-datepicker__month |
---|---|
Summary | Container of the month table |
Restrict | .slds-datepicker table |
Selector | .slds-day_adjacent-month |
---|---|
Summary | Indicates days that are in previous/next months |
Restrict | .slds-datepicker__month td |
Selector | .slds-has-multi-selection |
---|---|
Summary | Class on row to notify that more than one date will be selected within the week |
Support | dev-ready |
Restrict | .slds-datepicker tr |
Variant | True |
Selector | .slds-has-multi-row-selection |
---|---|
Summary | Class on row to notify that more than one date will be selected with multiple weeks |
Restrict | .slds-datepicker tr |
Selector | .slds-is-selected-multi |
---|---|
Summary | Indicates if the selected days are apart of a date range |
Restrict | .slds-datepicker td |
Datepickers Release Notes
2.17.0
Fixed
- Fixed missing attribute
required
on date input
2.16.0
Added
- Added examples for Required, Required with Error states
- Added hover style for dates
- Added
aria-label
to provide the fullDD MM YYYY
text of the date
Fixed
- Fixed missing attribute
aria-current="date"
when today's date falls inside of a selected range
2.14.1
Fixed
- Fixed typo in CSS Class Overview table for .slds-datepicker__filter_month
2.11.7
Fixed
- Resolved incorrect spacing when nested in a data table by increasing specificity of certain
slds-datepicker
specific CSS selectors
2.11.7
Changed
- Replaced
slds-disabled-text
with specific selectorslds-day_adjacent-month
for dates outside of current month, so that they will be selectable but with a different text color that meets accessibility requirements.