Skip to content

Commit 5601179

Browse files
committed
demo(list): Add accessibility demo page for list
1 parent 41c7157 commit 5601179

File tree

9 files changed

+167
-27
lines changed

9 files changed

+167
-27
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
} from './dialog/dialog-a11y';
2222

2323
import {GridListAccessibilityDemo} from './grid-list/grid-list-a11y';
24+
import {ListAccessibilityDemo} from './list/list-a11y';
2425
import {RadioAccessibilityDemo} from './radio/radio-a11y';
2526
import {ToolbarAccessibilityDemo} from './toolbar/toolbar-a11y';
2627
import {DatepickerAccessibilityDemo} from './datepicker/datepicker-a11y';
@@ -78,6 +79,7 @@ export class AccessibilityRoutingModule {}
7879
GridListAccessibilityDemo,
7980
IconAccessibilityDemo,
8081
InputAccessibilityDemo,
82+
ListAccessibilityDemo,
8183
MenuAccessibilityDemo,
8284
ProgressBarAccessibilityDemo,
8385
ProgressSpinnerAccessibilityDemo,

src/demo-app/a11y/a11y.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export class AccessibilityDemo {
3030
{name: 'Grid list', route: 'grid-list'},
3131
{name: 'Icon', route: 'icon'},
3232
{name: 'Input', route: 'input'},
33+
{name: 'List', route: 'list'},
3334
{name: 'Menu', route: 'menu'},
3435
{name: 'Progress bar', route: 'progress-bar'},
3536
{name: 'Progress spinner', route: 'progress-spinner'},

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
@@ -13,6 +13,7 @@ import {ToolbarAccessibilityDemo} from './toolbar/toolbar-a11y';
1313
import {DatepickerAccessibilityDemo} from './datepicker/datepicker-a11y';
1414
import {IconAccessibilityDemo} from './icon/icon-a11y';
1515
import {InputAccessibilityDemo} from './input/input-a11y';
16+
import {ListAccessibilityDemo} from './list/list-a11y';
1617
import {MenuAccessibilityDemo} from './menu/menu-a11y';
1718
import {ProgressBarAccessibilityDemo} from './progress-bar/progress-bar-a11y';
1819
import {ProgressSpinnerAccessibilityDemo} from './progress-spinner/progress-spinner-a11y';
@@ -36,6 +37,7 @@ export const ACCESSIBILITY_DEMO_ROUTES: Routes = [
3637
{path: 'grid-list', component: GridListAccessibilityDemo},
3738
{path: 'icon', component: IconAccessibilityDemo},
3839
{path: 'input', component: InputAccessibilityDemo},
40+
{path: 'list', component: ListAccessibilityDemo},
3941
{path: 'menu', component: MenuAccessibilityDemo},
4042
{path: 'progress-bar', component: ProgressBarAccessibilityDemo},
4143
{path: 'progress-spinner', component: ProgressSpinnerAccessibilityDemo},

src/lib/list/index.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
MdListIconCssMatStyler,
1919
MdListItem,
2020
MdListSubheaderCssMatStyler,
21-
MdNavListCssMatStyler
21+
MdNavList,
2222
} from './list';
2323
import {MdListOption, MdSelectionList} from './selection-list';
2424

@@ -28,12 +28,11 @@ import {MdListOption, MdSelectionList} from './selection-list';
2828
MdList,
2929
MdListItem,
3030
MdListDivider,
31+
MdNavList,
3132
MdListAvatarCssMatStyler,
3233
MdLineModule,
3334
MdCommonModule,
3435
MdListIconCssMatStyler,
35-
MdListCssMatStyler,
36-
MdNavListCssMatStyler,
3736
MdDividerCssMatStyler,
3837
MdListSubheaderCssMatStyler,
3938
MdPseudoCheckboxModule,
@@ -44,10 +43,9 @@ import {MdListOption, MdSelectionList} from './selection-list';
4443
MdList,
4544
MdListItem,
4645
MdListDivider,
46+
MdNavList,
4747
MdListAvatarCssMatStyler,
4848
MdListIconCssMatStyler,
49-
MdListCssMatStyler,
50-
MdNavListCssMatStyler,
5149
MdDividerCssMatStyler,
5250
MdListSubheaderCssMatStyler,
5351
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: 18 additions & 22 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() {

0 commit comments

Comments
 (0)