Skip to content

DatePicker

What component has

  • If the dropdown with the calendar grid opens, then the current date gets the focus.
  • If a date is selected, the accessible name of the "Date field" input is updated to include the selected date.

Keyboard support

Keyboard support
KeyFunction
TabMoves focus to the next focusable element. If the last element in the dropdown is focused, moves focus to the first element.
Shift + TabMoves focus to the previous focusable element. If the first element in the dropdown is focused, moves focus to the last element.
Enter, SpaceOpens the dropdown. When the dropdown is open and focus is on the calendar, applies the selected date and closes the dropdown.
EscCloses the dropdown and returns focus to the trigger.
Up Arrow, Down ArrowMoves selection to the same day of the previous or next week, respectively.
Left Arrow, Right ArrowMoves selection to the previous or next day, respectively.

Roles and attributes

The following list describes roles and attributes that the component already has.

Trigger

Trigger roles and attributes
Component / elementRole / AttributeUsage
DatePicker.Triggeraria-label="Date field"Defines the accessible name.
aria-controls="IDREF"Indicates which element this trigger opens.
role="combobox"Identifies the element as a combobox—a text input combined with a list of options.
aria-haspopup="dialog" and inherits aria-controls="IDREF" from its parent.aria-haspopup indicates that the element triggers a dialog.
aria-expanded="false/true"Indicates whether the dialog is open or not.
aria-describedby="IDREF"Provides the input with an accessible description by linking to a hint that explains the required data format.

Popper and its content

Roles and attributes of Popper and its content.
Component / elementRole / AttributeUsage
DatePicker.Popperrole="dialog"Identifies the element as a dialog, indicating that its content is grouped and separated from the rest of the page content.
DatePicker.Prevaria-label="Previous period"Defines the accessible name for the button.
DatePicker.Nextaria-label="Next period"Defines the accessible name for the button.
DatePicker.Titlearia-live="polite"Indicates that assistive technologies should automatically announce the displayed month and year when they change.
DateRangePicker.Periodrole="listbox"Identifies an element that creates a list from which a user may select one or more static items.

Calendar and days units

Calendar days units' roles and attributes
Component / elementRole / AttributeUsage
DatePicker.Calendar, MonthPeaker.Calendar, DatePicker.Calendar > divrole="grid"Identifies the calendar as a grid widget.
CalendarDays.Unitrole="gridcell"Identifies a cell in the grid. It's intended to mimic the functionality of the HTML <td> element.
aria-label is created from gridcell's content and DatePicker.TitleDefines the accessible name for the cell.
aria-selected="true/false"Indicates the cell or a number of cells is selected or not.
aria-disabled="false"Applies to gridcell with disabled prop. Indicates that the element is perceivable but disabled, so it's not operable.
aria-colindex="INDEX_VALUE"Applied when not all columns are present in the DOM. Defines an element's column index or position with respect to the total number of columns within the grid.
aria-rowindex="INDEX_VALUE"Applied when not all rows are present in the DOM. Defines an element's position with respect to the total number of rows within the grid.
CalendarWeekDaysrole="row"Identifies a row of cells within a tabular structure. A row contains one or more grid cells or column headers, within a grid.
CalendarWeekDays.Unitrole="columnheader"Identifies an element as a column header cell, similar to the native <th> element with column scope.

Resources

Other recommendations

For more accessibility recommendations, refer to the common Accessibility guide.

Released under the MIT License.

Released under the MIT License.