third_party/aria-practices/src/content/patterns/dialog-modal/examples/datepicker-dialog.html
The example below includes a date input field and a button that opens a date picker that implements the Dialog (Modal) Pattern. The dialog contains a calendar that uses the grid pattern to present buttons that enable the user to choose a day from the calendar. Choosing a date from the calendar closes the dialog and populates the date input field. When the dialog is opened, if the input field is empty, or does not contain a valid date, then the current date is focused in the calendar. Otherwise, the focus is placed on the day in the calendar that matches the value of the date input field.
Similar examples include:
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.abbr attribute on the column headers, enabling screen readers to announce the full names when users navigate the grid.| Key | Function |
|---|---|
| Space, | |
| Enter |
|
| Key | Function |
|---|---|
| ESC | Closes the dialog and returns focus to the "Choose Date" button. |
| Tab |
| | Shift + Tab |
|
| Key | Function |
|---|---|
| Space, | |
| Enter | Change the month and/or year displayed in the calendar 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. | | Page Up |
| | Shift + Page Up |
| | Page Down |
| | Shift + Page Down |
|
| Key | Function |
|---|---|
| Space, | |
| Enter | Activates the button: |
|
| Role | Attribute | Element | Usage |
|---|---|---|---|
aria-describedby="ID_REFERENCE" | input | Identifies the element that provides an accessible description for the textbox, enabling assistive technologies to associate the date format description with the input. |
| Role | Attribute | Element | Usage |
|---|---|---|---|
aria-label="String" | button |
|
| Role | Attribute | Element | Usage |
|---|---|---|---|
dialog | div | Identifies the element as a dialog . | |
aria-modal="true" | div | Indicates the dialog is modal. | |
aria-label="string" | div | Defines the accessible name for the dialog. | |
aria-live="polite" | h2 |
h2 element is updated.h2 should be automatically announced by screen readers.|
| | aria-live="polite" | div |
|
| 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="ID_REFERENCE" | table | Identifies the element that provides the accessible name for the grid. |
| | tabindex="0" | td |
gridcell within the grid is in the dialog Tab sequence.|
| | tabindex="-1" | td |
0 by the JavaScript when the cell is to be included in the dialog Tab sequence.gridcell within the grid is 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 a 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.