third_party/aria-practices/src/content/patterns/combobox/examples/combobox-datepicker.html
The below date picker demonstrates an implementation of the Combobox 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:
select element.aria-autocomplete=none.Date
(date format: mm/dd/yyyy)
| 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 |
CancelOK
aria-describedby, making it available to assistive technologies as an accessible description.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.abbr attribute on the column headers, enabling screen readers to announce the full names when users navigate the grid.| Key | Function |
|---|---|
| Down Arrow, | |
| ALT + Down Arrow |
|
| Key | Function |
|---|---|
| ESC | Closes the dialog and moves focus to the combobox. |
| TAB |
| | Shift + TAB |
|
| Key | Function |
|---|---|
| Space, | |
| Enter | Change the month and/or year displayed in the calendar grid. |
| Key | Function |
|---|---|
| Space |
combobox with the selected date.| | Enter |
combobox with the selected date.combobox.| | 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 |
|
| Key | Function |
|---|---|
| Space, | |
| Enter | Activates the button: |
|
| 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. |
| 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. |
| 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 |
polite value indicates that other announcements should not be interrupted.|
| | aria-live="polite" | div |
polite value indicates that other announcements should not be interrupted.|
| Role | Attribute | Element | Usage |
|---|---|---|---|
aria-label="String" | button | Defines the accessible name of the button (e.g. "Next Year"). |
| Role | Attribute | Element | Usage |
|---|---|---|---|
grid | table |
table element as a grid widget.grid role is applied to a table element, the row, columnheader, and gridcell roles do not need to be specified because they are implied by tr, th, and td tags.|
| | 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 |
0 by the JavaScript when the gridcell is to be included in the dialog Tab sequence.|
| | aria-selected="true" | td |
aria-selected specified.|
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.
To copy the following HTML code, please open it in CodePen.