Skip to content

Commit 4fcab57

Browse files
jelbournandrewseguin
authored andcommitted
docs(card): add guidance for a11y (#4781)
1 parent 223a27b commit 4fcab57

File tree

2 files changed

+47
-45
lines changed

2 files changed

+47
-45
lines changed

src/lib/card/card.md

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
`<md-card>` is a content container for text, photos, and actions. Cards are intended to provide
2-
information on a single subject.
1+
`<md-card>` is a content container for text, photos, and actions in the context of a single subject.
32

43
<!-- example(card-overview) -->
54

@@ -35,11 +34,42 @@ header to a card. This header can contain:
3534

3635

3736
### Title groups
38-
An `<md-card-title-group>` can be used to combine a title, subtitle, and image into a single section.
37+
`<md-card-title-group>` can be used to combine a title, subtitle, and image into a single section.
3938
This element can contain:
4039
* `<md-card-title>`
4140
* `<md-card-subtitle>`
4241
* One of:
4342
* `<img md-card-sm-image>`
4443
* `<img md-card-md-image>`
4544
* `<img md-card-lg-image>`
45+
46+
### Accessibility
47+
Cards can be used in a wide variety of scenarios and can contain many different types of content.
48+
Due to this dynamic nature, the appropriate accessibility treatment depends on how `<md-card>` is
49+
used.
50+
51+
#### Group, region, and landmarks
52+
There are several ARIA roles that communicate that a portion of the UI represents some semantically
53+
meaningful whole. Depending on what the content of the card means to your application,
54+
[`role="group"`][0], [`role="region"`][1], or [one of the landmark roles][3] should typically be
55+
applied to the `<md-card>` element.
56+
57+
A role is not necessary when the card is used as a purely decorative container that does not
58+
convey a meaningful grouping of related content for a single subject. In these cases, the content
59+
of the card should follow standard practices for document content.
60+
61+
62+
#### Focus
63+
Depending on how cards are used, it may be appropriate to apply a `tabindex` to the `<md-card>`
64+
element. If cards are a primary mechanism through which user interact with the application,
65+
`tabindex="0"` is appropriate. If attention can be sent to the card, but it's not part of the
66+
document flow, `tabindex="-1"` is appropriate.
67+
68+
If the card acts as a purely decorative container, it does not need to be tabbable. In this case,
69+
the card content should follow normal best practices for tab order.
70+
71+
72+
73+
[0]: https://www.w3.org/TR/wai-aria/roles#group
74+
[1]: https://www.w3.org/TR/wai-aria/roles#region
75+
[2]: https://www.w3.org/TR/wai-aria/roles#landmark

src/lib/card/card.ts

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ import {
1212
*/
1313
@Directive({
1414
selector: 'md-card-content, mat-card-content',
15-
host: {
16-
'[class.mat-card-content]': 'true'
17-
}
15+
host: {'class': 'mat-card-content'}
1816
})
1917
export class MdCardContent {}
2018

@@ -24,9 +22,7 @@ export class MdCardContent {}
2422
*/
2523
@Directive({
2624
selector: 'md-card-title, mat-card-title, [md-card-title], [mat-card-title]',
27-
host: {
28-
'[class.mat-card-title]': 'true'
29-
}
25+
host: {'class': 'mat-card-title'}
3026
})
3127
export class MdCardTitle {}
3228

@@ -36,9 +32,7 @@ export class MdCardTitle {}
3632
*/
3733
@Directive({
3834
selector: 'md-card-subtitle, mat-card-subtitle, [md-card-subtitle], [mat-card-subtitle]',
39-
host: {
40-
'[class.mat-card-subtitle]': 'true'
41-
}
35+
host: {'class': 'mat-card-subtitle'}
4236
})
4337
export class MdCardSubtitle {}
4438

@@ -48,9 +42,7 @@ export class MdCardSubtitle {}
4842
*/
4943
@Directive({
5044
selector: 'md-card-actions, mat-card-actions',
51-
host: {
52-
'[class.mat-card-actions]': 'true'
53-
}
45+
host: {'class': 'mat-card-actions'}
5446
})
5547
export class MdCardActions {}
5648

@@ -60,9 +52,7 @@ export class MdCardActions {}
6052
*/
6153
@Directive({
6254
selector: 'md-card-footer, mat-card-footer',
63-
host: {
64-
'[class.mat-card-footer]': 'true'
65-
}
55+
host: {'class': 'mat-card-footer'}
6656
})
6757
export class MdCardFooter {}
6858

@@ -72,9 +62,7 @@ export class MdCardFooter {}
7262
*/
7363
@Directive({
7464
selector: '[md-card-sm-image], [mat-card-sm-image]',
75-
host: {
76-
'[class.mat-card-sm-image]': 'true'
77-
}
65+
host: {'class': 'mat-card-sm-image'}
7866
})
7967
export class MdCardSmImage {}
8068

@@ -84,9 +72,7 @@ export class MdCardSmImage {}
8472
*/
8573
@Directive({
8674
selector: '[md-card-md-image], [mat-card-md-image]',
87-
host: {
88-
'[class.mat-card-md-image]': 'true'
89-
}
75+
host: {'class': 'mat-card-md-image'}
9076
})
9177
export class MdCardMdImage {}
9278

@@ -96,9 +82,7 @@ export class MdCardMdImage {}
9682
*/
9783
@Directive({
9884
selector: '[md-card-lg-image], [mat-card-lg-image]',
99-
host: {
100-
'class.mat-card-lg-image': 'true'
101-
}
85+
host: {'class': 'mat-card-lg-image'}
10286
})
10387
export class MdCardLgImage {}
10488

@@ -108,9 +92,7 @@ export class MdCardLgImage {}
10892
*/
10993
@Directive({
11094
selector: '[md-card-image], [mat-card-image]',
111-
host: {
112-
'[class.mat-card-image]': 'true'
113-
}
95+
host: {'class': 'mat-card-image'}
11496
})
11597
export class MdCardImage {}
11698

@@ -120,9 +102,7 @@ export class MdCardImage {}
120102
*/
121103
@Directive({
122104
selector: '[md-card-xl-image], [mat-card-xl-image]',
123-
host: {
124-
'[class.mat-card-xl-image]': 'true'
125-
}
105+
host: {'class': 'mat-card-xl-image'}
126106
})
127107
export class MdCardXlImage {}
128108

@@ -132,9 +112,7 @@ export class MdCardXlImage {}
132112
*/
133113
@Directive({
134114
selector: '[md-card-avatar], [mat-card-avatar]',
135-
host: {
136-
'[class.mat-card-avatar]': 'true'
137-
}
115+
host: {'class': 'mat-card-avatar'}
138116
})
139117
export class MdCardAvatar {}
140118

@@ -157,9 +135,7 @@ export class MdCardAvatar {}
157135
styleUrls: ['card.css'],
158136
encapsulation: ViewEncapsulation.None,
159137
changeDetection: ChangeDetectionStrategy.OnPush,
160-
host: {
161-
'[class.mat-card]': 'true'
162-
}
138+
host: {'class': 'mat-card'}
163139
})
164140
export class MdCard {}
165141

@@ -175,9 +151,7 @@ export class MdCard {}
175151
templateUrl: 'card-header.html',
176152
encapsulation: ViewEncapsulation.None,
177153
changeDetection: ChangeDetectionStrategy.OnPush,
178-
host: {
179-
'[class.mat-card-header]': 'true'
180-
}
154+
host: {'class': 'mat-card-header'}
181155
})
182156
export class MdCardHeader {}
183157

@@ -193,8 +167,6 @@ export class MdCardHeader {}
193167
templateUrl: 'card-title-group.html',
194168
encapsulation: ViewEncapsulation.None,
195169
changeDetection: ChangeDetectionStrategy.OnPush,
196-
host: {
197-
'[class.mat-card-title-group]': 'true'
198-
}
170+
host: {'class': 'mat-card-title-group'}
199171
})
200172
export class MdCardTitleGroup {}

0 commit comments

Comments
 (0)