Skip to content

Commit 7f9d0dd

Browse files
committed
demo(list): Add accessibility demo page for list
1 parent 9e35bf0 commit 7f9d0dd

File tree

8 files changed

+171
-22
lines changed

8 files changed

+171
-22
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
} from './dialog/dialog-a11y';
3030
import {ExpansionPanelAccessibilityDemo} from './expansion/expansion-a11y';
3131
import {GridListAccessibilityDemo} from './grid-list/grid-list-a11y';
32+
import {ListAccessibilityDemo} from './list/list-a11y';
3233
import {RadioAccessibilityDemo} from './radio/radio-a11y';
3334
import {ToolbarAccessibilityDemo} from './toolbar/toolbar-a11y';
3435
import {DatepickerAccessibilityDemo} from './datepicker/datepicker-a11y';
@@ -93,6 +94,7 @@ export class AccessibilityRoutingModule {}
9394
GridListAccessibilityDemo,
9495
IconAccessibilityDemo,
9596
InputAccessibilityDemo,
97+
ListAccessibilityDemo,
9698
MenuAccessibilityDemo,
9799
ProgressBarAccessibilityDemo,
98100
ProgressSpinnerAccessibilityDemo,

src/demo-app/a11y/a11y.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export class AccessibilityDemo implements OnDestroy {
4949
{name: 'Grid list', route: 'grid-list'},
5050
{name: 'Icon', route: 'icon'},
5151
{name: 'Input', route: 'input'},
52+
{name: 'List', route: 'list'},
5253
{name: 'Menu', route: 'menu'},
5354
{name: 'Progress bar', route: 'progress-bar'},
5455
{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
@@ -22,6 +22,7 @@ import {ToolbarAccessibilityDemo} from './toolbar/toolbar-a11y';
2222
import {DatepickerAccessibilityDemo} from './datepicker/datepicker-a11y';
2323
import {IconAccessibilityDemo} from './icon/icon-a11y';
2424
import {InputAccessibilityDemo} from './input/input-a11y';
25+
import {ListAccessibilityDemo} from './list/list-a11y';
2526
import {MenuAccessibilityDemo} from './menu/menu-a11y';
2627
import {ProgressBarAccessibilityDemo} from './progress-bar/progress-bar-a11y';
2728
import {ProgressSpinnerAccessibilityDemo} from './progress-spinner/progress-spinner-a11y';
@@ -52,6 +53,7 @@ export const ACCESSIBILITY_DEMO_ROUTES: Routes = [
5253
{path: 'grid-list', component: GridListAccessibilityDemo},
5354
{path: 'icon', component: IconAccessibilityDemo},
5455
{path: 'input', component: InputAccessibilityDemo},
56+
{path: 'list', component: ListAccessibilityDemo},
5557
{path: 'menu', component: MenuAccessibilityDemo},
5658
{path: 'progress-bar', component: ProgressBarAccessibilityDemo},
5759
{path: 'progress-spinner', component: ProgressSpinnerAccessibilityDemo},

src/lib/list/list.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,12 @@ To add a divider, use `<mat-divider>`.
150150
</mat-list-item>
151151
</mat-list>
152152
```
153+
154+
### Accessibility
155+
By default, the list assumes that it will be used in a purely decorative fashion and thus sets no
156+
roles, ARIA attributes, or keyboard shortcuts. This is equivalent to having a sequence of <div>
157+
elements on the page. Any interactive content within the list should be given an appropriate
158+
accessibility treatment based on the specific workflow of your application.
159+
160+
If the list is used to present a list of non-interactive content items, then the list element should
161+
be given `role="list"` and each list item should be given `role="listitem"`.

src/lib/list/list.ts

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,37 +44,33 @@ export class MatListDivider {}
4444
/** A Material Design list component. */
4545
@Component({
4646
moduleId: module.id,
47-
selector: 'mat-list, mat-nav-list',
48-
exportAs: 'matList, matNavList',
49-
host: {'role': 'list'},
47+
selector: 'mat-nav-list',
48+
exportAs: 'matNavList',
49+
host: {
50+
'role': 'navigation',
51+
'class': 'mat-nav-list'
52+
},
5053
template: '<ng-content></ng-content>',
5154
styleUrls: ['list.css'],
5255
inputs: ['disableRipple'],
5356
encapsulation: ViewEncapsulation.None,
5457
preserveWhitespaces: false,
5558
changeDetection: ChangeDetectionStrategy.OnPush,
5659
})
57-
export class MatList extends _MatListMixinBase implements CanDisableRipple {}
60+
export class MatNavList extends _MatListMixinBase implements CanDisableRipple {}
5861

59-
/**
60-
* Directive whose purpose is to add the mat- CSS styling to this selector.
61-
* @docs-private
62-
*/
63-
@Directive({
62+
@Component({
63+
moduleId: module.id,
6464
selector: 'mat-list',
65-
host: {'class': 'mat-list'}
66-
})
67-
export class MatListCssMatStyler {}
68-
69-
/**
70-
* Directive whose purpose is to add the mat- CSS styling to this selector.
71-
* @docs-private
72-
*/
73-
@Directive({
74-
selector: 'mat-nav-list',
75-
host: {'class': 'mat-nav-list'}
65+
exportAs: 'matList',
66+
template: '<ng-content></ng-content>',
67+
host: {'class': 'mat-list'},
68+
styleUrls: ['list.css'],
69+
inputs: ['disableRipple'],
70+
encapsulation: ViewEncapsulation.None,
71+
changeDetection: ChangeDetectionStrategy.OnPush,
7672
})
77-
export class MatNavListCssMatStyler {}
73+
export class MatList extends _MatListMixinBase implements CanDisableRipple {}
7874

7975
/**
8076
* Directive whose purpose is to add the mat- CSS styling to this selector.
@@ -149,11 +145,18 @@ export class MatListItem extends _MatListItemMixinBase implements AfterContentIn
149145
}
150146
}
151147

148+
<<<<<<< HEAD
152149
constructor(private _element: ElementRef,
153150
@Optional() private _list: MatList,
154151
@Optional() navList: MatNavListCssMatStyler) {
152+
=======
153+
constructor(private _renderer: Renderer2,
154+
private _element: ElementRef,
155+
@Optional() private _list: MdList,
156+
@Optional() private _navList: MdNavList) {
157+
>>>>>>> demo(list): Add accessibility demo page for list
155158
super();
156-
this._isNavList = !!navList;
159+
this._isNavList = !!_navList;
157160
}
158161

159162
ngAfterContentInit() {

0 commit comments

Comments
 (0)