Date Picker Combobox Example
The below date picker demonstrates an implementation of the combobox design pattern that opens a dialog. The date picker dialog is opened by activating the choose date button or by moving keyboard focus to the combobox and pressing Down Arrow or Alt + Down Arrow. The dialog contains an implementation of the grid pattern for displaying a calendar and enabling selection of a date. Additional buttons in the dialog are available for changing the month and year shown in the grid.
Similar examples include:
- Date Picker Dialog example: Demonstrates a dialog containing a calendar grid for choosing a date.
- Select-Only Combobox: A single-select combobox with no text input that is functionally similar to an HTML
select
element. - Editable Combobox with Both List and Inline Autocomplete: An editable combobox that demonstrates the autocomplete behavior known as "list with inline autocomplete".
- Editable Combobox with List Autocomplete: An editable combobox that demonstrates the autocomplete behavior known as "list with manual selection".
- Editable Combobox Without Autocomplete: An editable combobox that demonstrates the behavior associated with
aria-autocomplete=none
. - Editable Combobox with Grid Popup: An editable combobox that presents suggestions in a grid, enabling users to navigate descriptive information about each suggestion.
Example
December 2020
Su | Mo | Tu | We | Th | Fr | Sa |
---|---|---|---|---|---|---|
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 | 31 |
Accessibility Features
- The description of the date format is associated with the combobox via
aria-describedby
, making it available to assistive technologies as an accessible description. -
While the down arrow icon is excluded from the Tab sequence as specified in the
combobox
design pattern, it is made accessible to assistive technologies as the Choose Date button. This enables assistive technology users who might not have a keyboard, e.g., someone using a touch-based screen reader, to open the date picker dialog. - In the dialog, shortcut keys are assigned to the additional buttons for changing the month and year displayed in the calendar.
- Keyboard help is displayed at the bottom of the dialog. A live region is used to announce it to screen reader users when focus moves into the grid.
- The calendar heading displaying the month and year is marked up as a live region so screen reader users get feedback from the buttons and keyboard commands that change the month and year.
-
To facilitate compact visual design in the calendar, the day names in the column headers are abbreviated to two characters.
However, this makes it more difficult for screen reader users to understand the day names.
So, full day names are provided to assistive technologies in the HTML
abbr
attribute on the column headers, enabling screen readers to announce the full names when users navigate the grid. - Focus and hover styling of the controls support operating system high contrast settings via the CSS border property:
- When a button or date cell receives focus a border is added.
- When hovering over a button or date cell with a pointing device a border is added.
- By default, buttons and date cells do not have a border; padding provides a placeholder space for focus and hover styling.
Keyboard Support
Combobox
Key | Function |
---|---|
Down Arrow, ALT + Down Arrow |
|
Date Picker Dialog
Key | Function |
---|---|
ESC | Closes the dialog and moves focus to the combobox. |
TAB |
|
Shift + TAB |
|
Date Picker Dialog: Calendar Buttons
Key | Function |
---|---|
Space, Enter |
Change the month and/or year displayed in the calendar grid. |
Date Picker Dialog: Date Grid
Key | Function |
---|---|
Space |
|
Enter |
|
Up Arrow | Moves focus to the same day of the previous week. |
Down Arrow | Moves focus to the same day of the next week. |
Right Arrow | Moves focus to the next day. |
Left Arrow | Moves focus to the previous day. |
Home | Moves focus to the first day (e.g. Sunday) of the current week. |
End | Moves focus to the last day (e.g. Saturday) of the current week. |
PageUp |
|
Shift+ PageUp |
|
PageDown |
|
Shift+ PageDown |
|
Date Picker Dialog: OK and Cancel Buttons
Key | Function |
---|---|
Space, Enter |
Activates the button:
|
Role, Property, State, and Tabindex Attributes
Combobox
Role | Attribute | Element | Usage |
---|---|---|---|
combobox |
input |
Identifies the input element as a combobox.
|
|
aria-haspopup="dialog" |
input |
Indicates that the combobox opens a dialog. | |
aria-expanded="false" |
input |
Indicates that the combobox is collapsed, i.e., the "Choose Date" dialog is not displayed. | |
aria-expanded="true" |
input |
Indicates that the combobox is expanded, i.e., the "Choose Date" dialog is open. | |
aria-autocomplete="none" |
input |
Indicates the combobox does not support autocomplete. | |
aria-controls="IDREF" |
input |
Identifies the element controlled by the combobox. | |
aria-describedby="IDREF" |
input |
Identifies the element that provides an accessible description for the combobox, enabling assistive technologies to associate the date format description with the input. |
Choose Date Button
Role | Attribute | Element | Usage |
---|---|---|---|
tabindex="-1" |
button |
Excludes the button (i.e., the down arrow icon) from the Tab sequence as specified by the combobox design pattern. | |
aria-label="string" |
button |
Defines the accessible name as "Choose Date", which matches the title of the dialog opened by activating the button. |
Date Picker Dialog
Role | Attribute | Element | Usage |
---|---|---|---|
dialog |
div
|
Identifies the element as a dialog. | |
aria-modal="true" |
div |
Indicates the dialog is modal. | |
aria-label="Choose Date" |
div |
Defines the accessible name for the dialog. | |
aria-live="polite" |
h2 |
|
|
aria-live="polite" |
div |
|
Date Picker Dialog: Calendar Navigation Buttons
Role | Attribute | Element | Usage |
---|---|---|---|
aria-label="String" |
button |
Defines the accessible name of the button (e.g. "Next Year"). |
Date Picker Dialog: Date Grid
Role | Attribute | Element | Usage |
---|---|---|---|
grid |
table
|
|
|
aria-labelledby="IDREF" |
table |
Identifies the element that provides the accessible name for the grid , which is the h2 that shows the month and year of the dates displayed in the grid.
|
|
tabindex="0"
|
td
|
|
|
tabindex="-1"
|
td
|
|
|
aria-selected="true" |
td |
|
Note: Since the names of the days of the week in the column headers are abbreviated to two characters, they may be difficult to understand when announced by a screen reader.
An alternative column header name can be provided to screen readers by applying the abbr
attribute to the th
elements.
So, each th
element includes an abbr
attribute containing the full spelling of the name of the day for that column.
Javascript and CSS Source Code
- CSS: combobox-datepicker.css
- Javascript: combobox-datepicker.js
HTML Source Code