Skip to content

Commit d3f091a

Browse files
tinayuangaojosephperrott
authored andcommitted
docs(a11y): add accessibility sections to datepicker, menu, slide … (angular#6710)
1 parent cd16ec6 commit d3f091a

File tree

11 files changed

+98
-11
lines changed

11 files changed

+98
-11
lines changed

src/demo-app/expansion/expansion-demo.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,16 @@ <h1>Accordion</h1>
2727
<p>Accordion Options</p>
2828
<div>
2929
<md-slide-toggle [(ngModel)]="multi">Allow Multi Expansion</md-slide-toggle>
30-
<md-slide-toggle [(ngModel)]="hideToggle">Hide Indicators</md-slide-toggle>
3130
<md-slide-toggle [(ngModel)]="disabled">Disable Panel 2</md-slide-toggle>
3231
<md-slide-toggle [(ngModel)]="showPanel3">Show Panel 3</md-slide-toggle>
3332
</div>
33+
<div>
34+
<md-radio-group [(ngModel)]="hideToggle">
35+
<md-radio-button value="start">Start</md-radio-button>
36+
<md-radio-button value="end">End</md-radio-button>
37+
<md-radio-button value="hidden">Hidden</md-radio-button>
38+
</md-radio-group>
39+
</div>
3440
<p>Accordion Style</p>
3541
<md-radio-group [(ngModel)]="displayMode">
3642
<md-radio-button value="default">Default</md-radio-button>

src/lib/datepicker/datepicker.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,52 @@ application root module.
229229
})
230230
export class MyApp {}
231231
```
232+
### Accessibility
233+
The `MdDatepickerInput` directive adds `aria-haspopup` attribute to the native input element, and it
234+
triggers a calendar dialog with `role="dialog"`.
235+
236+
`MdDatepickerIntl` includes strings that are used for `aria-label`s. The datepicker input
237+
should have a placeholder or be given a meaningful label via `aria-label`, `aria-labelledby` or
238+
`MdDatepickerIntl`.
239+
240+
#### Keyboard shortcuts
241+
The keyboard shortcuts to handle datepicker are:
242+
243+
| Shortcut | Action |
244+
|----------------------|-------------------------------------|
245+
| `ALT` + `DOWN_ARROW` | Open the calendar pop-up |
246+
| `ESCAPE` | Close the calendar pop-up |
247+
248+
249+
In month view:
250+
251+
| Shortcut | Action |
252+
|----------------------|-------------------------------------|
253+
| `LEFT_ARROW` | Go to previous day |
254+
| `RIGHT_ARROW` | Go to next day |
255+
| `UP_ARROW` | Go to same day in the previous week |
256+
| `DOWN_ARROW` | Go to same day in the next week |
257+
| `HOME` | Go to the first day of the month |
258+
| `END` | Go to the last day of the month |
259+
| `PAGE_UP` | Go to previous month |
260+
| `ALT` + `PAGE_UP` | Go to previous year |
261+
| `PAGE_DOWN` | Go to next month |
262+
| `ALT` + `PAGE_DOWN` | Go to next year |
263+
| `ENTER` | Select current date |
264+
265+
266+
In year view:
267+
268+
| Shortcut | Action |
269+
|----------------------|-------------------------------------|
270+
| `LEFT_ARROW` | Go to previous month |
271+
| `RIGHT_ARROW` | Go to next month |
272+
| `UP_ARROW` | Go to previous 6 months |
273+
| `DOWN_ARROW` | Go to next 6 months |
274+
| `HOME` | Go to the first month of the year |
275+
| `END` | Go to the last month of the year |
276+
| `PAGE_UP` | Go to previous year |
277+
| `ALT` + `PAGE_UP` | Go to previous 10 years |
278+
| `PAGE_DOWN` | Go to next year |
279+
| `ALT` + `PAGE_DOWN` | Go to next 10 years |
280+
| `ENTER` | Select current month |

src/lib/expansion/accordion.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ export class CdkAccordion {
3131
private _multi: boolean = false;
3232

3333
/** Whether the expansion indicator should be hidden. */
34-
@Input() get hideToggle(): boolean { return this._hideToggle; }
35-
set hideToggle(show: boolean) { this._hideToggle = coerceBooleanProperty(show); }
36-
private _hideToggle: boolean = false;
34+
@Input() hideToggle = 'end';
3735

3836
/**
3937
* The display mode used for all expansion panels in the accordion. Currently two display

src/lib/expansion/expansion-panel-header.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
<ng-content select="md-panel-description, mat-panel-description"></ng-content>
44
<ng-content></ng-content>
55
</span>
6-
<span [@indicatorRotate]="_getExpandedState()" *ngIf="_showToggle()"
6+
<span [@indicatorRotate]="_getExpandedState()" *ngIf="_indicatorLocation() !== 'hidden'"
77
class="mat-expansion-indicator"></span>

src/lib/expansion/expansion-panel-header.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,11 @@ export class MdExpansionPanelHeader implements OnDestroy {
137137
}
138138

139139
/** Gets whether the expand indicator should be shown. */
140-
_showToggle(): boolean {
141-
return !this.panel.hideToggle && !this.panel.disabled;
140+
_indicatorLocation(): string {
141+
if (this.panel.disabled) {
142+
return 'hidden';
143+
}
144+
return this.panel.hideToggle;
142145
}
143146

144147
/** Handle keyup event calling to toggle() if appropriate. */

src/lib/expansion/expansion-panel.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export const EXPANSION_PANEL_ANIMATION_TIMING = '225ms cubic-bezier(0.4,0.0,0.2,
7373
})
7474
export class MdExpansionPanel extends AccordionItem implements OnChanges, OnDestroy {
7575
/** Whether the toggle indicator should be hidden. */
76-
@Input() hideToggle: boolean = false;
76+
@Input() hideToggle: string = 'end';
7777

7878
/** Stream that emits for changes in `@Input` properties. */
7979
_inputChanges = new Subject<SimpleChanges>();
@@ -86,11 +86,11 @@ export class MdExpansionPanel extends AccordionItem implements OnChanges, OnDest
8686
}
8787

8888
/** Whether the expansion indicator should be hidden. */
89-
_getHideToggle(): boolean {
89+
_getHideToggle(): string {
9090
if (this.accordion) {
91-
return this.accordion.hideToggle;
91+
return this.accordion.hideToggle ? '' : 'hidden';
9292
}
93-
return this.hideToggle;
93+
return this.hideToggle ? '' : 'hidden';
9494
}
9595

9696
/** Determines whether the expansion panel should have spacing between it and its siblings. */

src/lib/menu/menu.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,7 @@ that should trigger the sub-menu:
9898
- <kbd>RIGHT_ARROW</kbd>: Opens the menu item's sub-menu
9999
- <kbd>LEFT_ARROW</kbd>: Closes the current menu, if it is a sub-menu.
100100
- <kbd>ENTER</kbd>: Activates the focused menu item
101+
102+
### Accessibility
103+
Menu triggers or menu items without text or labels should be given a meaningful label via
104+
`aria-label` or `aria-labelledby`.

src/lib/slide-toggle/slide-toggle.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,11 @@ and `ReactiveFormsModule`.
2222
### Theming
2323
The color of a `<md-slide-toggle>` can be changed by using the `color` property. By default,
2424
slide-toggles use the theme's accent color. This can be changed to `'primary'` or `'warn'`.
25+
26+
### Accessibility
27+
The `<md-slide-toggle>` uses an internal `<input type="checkbox">` to provide an accessible
28+
experience. This internal checkbox receives focus and is automatically labelled by the text content
29+
of the `<md-slide-toggle>` element.
30+
31+
Slide toggles without text or labels should be given a meaningful label via `aria-label` or
32+
`aria-labelledby`.

src/lib/slider/slider.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,7 @@ The slider has the following keyboard bindings:
8585
| Page down | Decrement the slider value by 10 steps. |
8686
| End | Set the value to the maximum possible. |
8787
| Home | Set the value to the minimum possible. |
88+
89+
### Accessibility
90+
Sliders without text or labels should be given a meaningful label via `aria-label` or
91+
`aria-labelledby`.

src/lib/snack-bar/snack-bar.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,8 @@ export class MessageArchivedComponent {
7272
constructor(@Inject(MD_SNACK_BAR_DATA) public data: any) { }
7373
}
7474
```
75+
### Accessibility
76+
Snack-bar messages are announced via an `aria-live` region. Focus is not moved to
77+
the snack-bar element, as this would be disruptive to a user in the middle of a
78+
workflow. For any action offered in the snack-bar, the application should offer the
79+
user an alternative way to perform the action (typically via keyboard shortcut).

src/lib/toolbar/toolbar.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,13 @@ easily accomplished with `display: flex`:
4949
The color of a `<md-toolbar>` can be changed by using the `color` property. By default, toolbars
5050
use a neutral background color based on the current theme (light or dark). This can be changed to
5151
`'primary'`, `'accent'`, or `'warn'`.
52+
53+
### Accessibility
54+
By default, the toolbar assumes that it will be used in a purely decorative fashion and thus sets
55+
no roles, ARIA attributes, or keyboard shortcuts. This is equivalent to having a sequence of `<div>`
56+
elements on the page.
57+
58+
Generally, the toolbar is used as a header where `role="header"` would be appropriate.
59+
60+
Only if the use-case of the toolbar match that of role="toolbar", the user should add the role and
61+
an appropriate label via `aria-label` or `aria-labelledby`.

0 commit comments

Comments
 (0)