Skip to content

Commit a37aa6a

Browse files
crisbetommalerba
authored andcommitted
fix(chips): set appropriate aria-orientation (#6464)
Based on the [accessibility guidelines](https://www.w3.org/TR/wai-aria-practices-1.1/#Listbox), the `listbox` role has a default `aria-orientation` of `vertical`, however the chips in a chip list are horizontal.
1 parent ba2f498 commit a37aa6a

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/demo-app/chips/chips-demo.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ <h4>Stacked Chips</h4>
102102
<code>(focus)</code> event to run custom code.
103103
</p>
104104

105-
<md-chip-list class="mat-chip-list-stacked" [tabIndex]="-1">
105+
<md-chip-list class="mat-chip-list-stacked" aria-orientation="vertical" [tabIndex]="-1">
106106
<md-chip *ngFor="let aColor of availableColors"
107107
(focus)="color = aColor.color" color="{{aColor.color}}" selected="true">
108108
{{aColor.name}}

src/lib/chips/chip-list.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import {coerceBooleanProperty} from '@angular/cdk/coercion';
4545
host: {
4646
'[attr.tabindex]': '_tabIndex',
4747
'role': 'listbox',
48+
'[attr.aria-orientation]': 'ariaOrientation',
4849
'class': 'mat-chip-list',
4950

5051
'(focus)': 'focus()',
@@ -88,6 +89,9 @@ export class MdChipList implements AfterContentInit, OnDestroy {
8889
/** The chip components contained within this chip list. */
8990
chips: QueryList<MdChip>;
9091

92+
/** Orientation of the chip list. */
93+
@Input('aria-orientation') ariaOrientation: 'horizontal' | 'vertical' = 'horizontal';
94+
9195
constructor(protected _renderer: Renderer2, protected _elementRef: ElementRef,
9296
@Optional() private _dir: Directionality) {
9397
}

src/lib/chips/chips.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,21 @@ chips are neither selectable nor focusable. Currently, disabled chips receive no
3333
Users can move through the chips using the arrow keys and select/deselect them with the space. Chips
3434
also gain focus when clicked, ensuring keyboard navigation starts at the appropriate chip.
3535

36+
### Orientation
37+
If you want the chips in the list to be stacked vertically, instead of horizontally, you can apply
38+
the `mat-chip-list-stacked` class, as well as the `aria-orientation="vertical"` attribute:
39+
40+
```html
41+
<md-chip-list class="mat-chip-list-stacked" aria-orientation="vertical">
42+
<md-chip>Papadum</md-chip>
43+
<md-chip>Naan</md-chip>
44+
<md-chip>Dal</md-chip>
45+
</md-chip-list>
46+
```
3647

3748
### Theming
3849
The selected color of an `<md-chip>` can be changed by using the `color` property. By default, chips
39-
use a neutral background color based on the current theme (light or dark). This can be changed to
50+
use a neutral background color based on the current theme (light or dark). This can be changed to
4051
`'primary'`, `'accent'`, or `'warn'`.
4152

4253
### Accessibility

0 commit comments

Comments
 (0)