Skip to content

Commit 3d74068

Browse files
committed
demo(list): Add accessibility demo page for list
1 parent 372436c commit 3d74068

File tree

9 files changed

+168
-29
lines changed

9 files changed

+168
-29
lines changed

src/demo-app/a11y/a11y-module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {ButtonToggleAccessibilityDemo} from './button-toggle/button-toggle-a11y'
1111
import {CheckboxAccessibilityDemo} from './checkbox/checkbox-a11y';
1212
import {ChipsAccessibilityDemo} from './chips/chips-a11y';
1313
import {GridListAccessibilityDemo} from './grid-list/grid-list-a11y';
14+
import {ListAccessibilityDemo} from './list/list-a11y';
1415
import {RadioAccessibilityDemo} from './radio/radio-a11y';
1516
import {DatepickerAccessibilityDemo} from './datepicker/datepicker-a11y';
1617
import {IconAccessibilityDemo} from './icon/icon-a11y';
@@ -50,6 +51,7 @@ export class AccessibilityRoutingModule {}
5051
GridListAccessibilityDemo,
5152
IconAccessibilityDemo,
5253
InputAccessibilityDemo,
54+
ListAccessibilityDemo,
5355
ProgressSpinnerAccessibilityDemo,
5456
RadioAccessibilityDemo,
5557
SliderAccessibilityDemo,

src/demo-app/a11y/a11y.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export class AccessibilityDemo {
2626
{name: 'Grid list', route: 'grid-list'},
2727
{name: 'Icon', route: 'icon'},
2828
{name: 'Input', route: 'input'},
29+
{name: 'List', route: 'list'},
2930
{name: 'Progress spinner', route: 'progress-spinner'},
3031
{name: 'Radio buttons', route: 'radio'},
3132
{name: 'Slider', route: 'slider'},

src/demo-app/a11y/list/list-a11y.html

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<div class="demo-list">
2+
<section>
3+
<h2> Seasoning </h2>
4+
<p>Showing a non-interactive list of seasonings.</p>
5+
<md-list role="list">
6+
<md-list-item *ngFor="let item of items"> {{item}} </md-list-item>
7+
</md-list>
8+
</section>
9+
10+
11+
<section>
12+
<h2>Mailbox navigation</h2>
13+
<p>Showing a navigation list with links to google search</p>
14+
<md-nav-list>
15+
<a md-list-item *ngFor="let link of links"
16+
href="https://www.google.com/search?q={{link.name}}">
17+
{{link.name}}
18+
</a>
19+
</md-nav-list>
20+
</section>
21+
22+
<section>
23+
<h2>Messages</h2>
24+
<p>
25+
Showing a list of messages, where each message item has sender's name, sender's avatar,
26+
message subject, and content of the message.
27+
</p>
28+
<md-list role="list">
29+
<md-list-item *ngFor="let message of messages">
30+
<img md-list-avatar [src]="message.image" [alt]="message.from">
31+
<h3 md-line> {{message.from}} </h3>
32+
<p md-line> {{message.subject}} </p>
33+
<p md-line class="demo-secondary-text"> {{message.message}} </p>
34+
</md-list-item>
35+
</md-list>
36+
37+
</section>
38+
39+
<section>
40+
<h2>Seasoning</h2>
41+
<p>Showing a non-interactive list of seasonings with dense style.</p>
42+
<md-list dense>
43+
<md-list-item *ngFor="let item of items"> {{item}} </md-list-item>
44+
</md-list>
45+
</section>
46+
47+
<section>
48+
<h2>Folders and notes for mailbox </h2>
49+
<p>Showing a list with two sections, "folders" and "notes".</p>
50+
<md-list role="list">
51+
<h3 md-subheader>Folders</h3>
52+
<md-list-item *ngFor="let folder of folders">
53+
<md-icon md-list-icon>folder</md-icon>
54+
<h4 md-line>{{folder.name}}</h4>
55+
<p md-line class="demo-secondary-text"> {{folder.updated}} </p>
56+
</md-list-item>
57+
<md-divider></md-divider>
58+
<h3 md-subheader>Notes</h3>
59+
<md-list-item *ngFor="let note of notes">
60+
<md-icon md-list-icgon>note</md-icon>
61+
<h4 md-line>{{note.name}}</h4>
62+
<p md-line class="demo-secondary-text"> {{note.updated}} </p>
63+
</md-list-item>
64+
</md-list>
65+
</section>
66+
</div>

src/demo-app/a11y/list/list-a11y.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.demo-list {
2+
.mat-list, .mat-nav-list {
3+
border: 1px solid rgba(0, 0, 0, 0.12);
4+
max-width: 350px;
5+
margin: 20px 20px 0 0;
6+
}
7+
8+
.demo-secondary-text {
9+
color: rgba(0, 0, 0, 0.54);
10+
}
11+
}

src/demo-app/a11y/list/list-a11y.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import {Component} from '@angular/core';
2+
3+
@Component({
4+
moduleId: module.id,
5+
selector: 'list-a11y',
6+
templateUrl: 'list-a11y.html',
7+
styleUrls: ['list-a11y.css']
8+
})
9+
export class ListAccessibilityDemo {
10+
items: string[] = [
11+
'Pepper',
12+
'Salt',
13+
'Paprika'
14+
];
15+
16+
messages = [
17+
{
18+
from: 'Nancy',
19+
subject: 'Brunch?',
20+
message: 'Did you want to go on Sunday? I was thinking that might work.',
21+
image: 'https://angular.io/generated/images/bios/julie-ralph.jpg'
22+
},
23+
{
24+
from: 'Mary',
25+
subject: 'Summer BBQ',
26+
message: 'Wish I could come, but I have some prior obligations.',
27+
image: 'https://angular.io/generated/images/bios/juleskremer.jpg'
28+
},
29+
{
30+
from: 'Bobby',
31+
subject: 'Oui oui',
32+
message: 'Do you have Paris reservations for the 15th? I just booked!',
33+
image: 'https://angular.io/generated/images/bios/jelbourn.jpg'
34+
}
35+
];
36+
37+
links = [
38+
{name: 'Inbox'},
39+
{name: 'Outbox'},
40+
{name: 'Spam'},
41+
{name: 'Trash'}
42+
43+
];
44+
45+
folders = [
46+
{name: 'Imported', updated: 'Miles'},
47+
{name: 'Important', updated: 'Tina'},
48+
{name: 'Unread', updated: 'Jeremy'},
49+
];
50+
51+
notes = [
52+
{name: 'Update screenshots', updated: 'Kara'},
53+
{name: 'Install new application', updated: 'Andrew'},
54+
];
55+
}

src/demo-app/a11y/routes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {AccessibilityHome} from './a11y';
1010
import {DatepickerAccessibilityDemo} from './datepicker/datepicker-a11y';
1111
import {IconAccessibilityDemo} from './icon/icon-a11y';
1212
import {InputAccessibilityDemo} from './input/input-a11y';
13+
import {ListAccessibilityDemo} from './list/list-a11y';
1314
import {ProgressSpinnerAccessibilityDemo} from './progress-spinner/progress-spinner-a11y';
1415
import {SliderAccessibilityDemo} from './slider/slider-a11y';
1516
import {SnackBarAccessibilityDemo} from './snack-bar/snack-bar-a11y';
@@ -25,6 +26,7 @@ export const ACCESSIBILITY_DEMO_ROUTES: Routes = [
2526
{path: 'grid-list', component: GridListAccessibilityDemo},
2627
{path: 'icon', component: IconAccessibilityDemo},
2728
{path: 'input', component: InputAccessibilityDemo},
29+
{path: 'list', component: ListAccessibilityDemo},
2830
{path: 'progress-spinner', component: ProgressSpinnerAccessibilityDemo},
2931
{path: 'radio', component: RadioAccessibilityDemo},
3032
{path: 'slider', component: SliderAccessibilityDemo},

src/lib/list/index.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ import {
1313
MdList,
1414
MdListItem,
1515
MdListDivider,
16+
MdNavList,
1617
MdListAvatarCssMatStyler,
1718
MdListIconCssMatStyler,
18-
MdListCssMatStyler,
19-
MdNavListCssMatStyler,
2019
MdDividerCssMatStyler,
2120
MdListSubheaderCssMatStyler
2221
} from './list';
@@ -29,12 +28,11 @@ import {MdSelectionList, MdListOption} from './selection-list';
2928
MdList,
3029
MdListItem,
3130
MdListDivider,
31+
MdNavList,
3232
MdListAvatarCssMatStyler,
3333
MdLineModule,
3434
MdCommonModule,
3535
MdListIconCssMatStyler,
36-
MdListCssMatStyler,
37-
MdNavListCssMatStyler,
3836
MdDividerCssMatStyler,
3937
MdListSubheaderCssMatStyler,
4038
MdSelectionModule,
@@ -45,10 +43,9 @@ import {MdSelectionList, MdListOption} from './selection-list';
4543
MdList,
4644
MdListItem,
4745
MdListDivider,
46+
MdNavList,
4847
MdListAvatarCssMatStyler,
4948
MdListIconCssMatStyler,
50-
MdListCssMatStyler,
51-
MdNavListCssMatStyler,
5249
MdDividerCssMatStyler,
5350
MdListSubheaderCssMatStyler,
5451
MdSelectionList,

src/lib/list/list.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,12 @@ To add a divider, use `<md-divider>`.
141141
</md-list-item>
142142
</md-list>
143143
```
144+
145+
### Accessibility
146+
By default, the list assumes that it will be used in a purely decorative fashion and thus sets no
147+
roles, ARIA attributes, or keyboard shortcuts. This is equivalent to having a sequence of <div>
148+
elements on the page. Any interactive content within the list should be given an appropriate
149+
accessibility treatment based on the specific workflow of your application.
150+
151+
If the list is used to present a list of non-interactive content items, then the list element should
152+
be given `role="list"` and each list item should be given `role="listitem"`.

src/lib/list/list.ts

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,37 +42,33 @@ export const _MdListItemMixinBase = mixinDisableRipple(MdListItemBase);
4242
})
4343
export class MdListDivider {}
4444

45+
4546
@Component({
4647
moduleId: module.id,
47-
selector: 'md-list, mat-list, md-nav-list, mat-nav-list',
48-
host: {'role': 'list'},
48+
selector: 'md-nav-list, mat-nav-list',
49+
host: {
50+
'role': 'navigation',
51+
'class': 'mat-nav-list'
52+
},
4953
template: '<ng-content></ng-content>',
5054
styleUrls: ['list.css'],
5155
inputs: ['disableRipple'],
5256
encapsulation: ViewEncapsulation.None,
5357
changeDetection: ChangeDetectionStrategy.OnPush,
5458
})
55-
export class MdList extends _MdListMixinBase implements CanDisableRipple {}
59+
export class MdNavList extends _MdListMixinBase implements CanDisableRipple {}
5660

57-
/**
58-
* Directive whose purpose is to add the mat- CSS styling to this selector.
59-
* @docs-private
60-
*/
61-
@Directive({
61+
@Component({
62+
moduleId: module.id,
6263
selector: 'md-list, mat-list',
63-
host: {'class': 'mat-list'}
64-
})
65-
export class MdListCssMatStyler {}
66-
67-
/**
68-
* Directive whose purpose is to add the mat- CSS styling to this selector.
69-
* @docs-private
70-
*/
71-
@Directive({
72-
selector: 'md-nav-list, mat-nav-list',
73-
host: {'class': 'mat-nav-list'}
64+
template: '<ng-content></ng-content>',
65+
host: {'class': 'mat-list'},
66+
styleUrls: ['list.css'],
67+
inputs: ['disableRipple'],
68+
encapsulation: ViewEncapsulation.None,
69+
changeDetection: ChangeDetectionStrategy.OnPush,
7470
})
75-
export class MdNavListCssMatStyler {}
71+
export class MdList extends _MdListMixinBase implements CanDisableRipple {}
7672

7773
/**
7874
* Directive whose purpose is to add the mat- CSS styling to this selector.
@@ -146,9 +142,9 @@ export class MdListItem extends _MdListItemMixinBase implements AfterContentInit
146142
constructor(private _renderer: Renderer2,
147143
private _element: ElementRef,
148144
@Optional() private _list: MdList,
149-
@Optional() navList: MdNavListCssMatStyler) {
145+
@Optional() private _navList: MdNavList) {
150146
super();
151-
this._isNavList = !!navList;
147+
this._isNavList = !!_navList;
152148
}
153149

154150
ngAfterContentInit() {
@@ -157,7 +153,7 @@ export class MdListItem extends _MdListItemMixinBase implements AfterContentInit
157153

158154
/** Whether this list item should show a ripple effect when clicked. */
159155
isRippleEnabled() {
160-
return !this.disableRipple && this._isNavList && !this._list.disableRipple;
156+
return !this.disableRipple && this._isNavList && !this._navList.disableRipple;
161157
}
162158

163159
_handleFocus() {

0 commit comments

Comments
 (0)