File tree 3 files changed +61
-34
lines changed
src/compiler/compile/nodes
test/validator/samples/a11y-media-has-caption 3 files changed +61
-34
lines changed Original file line number Diff line number Diff line change @@ -287,6 +287,29 @@ export default class Element extends Node {
287
287
}
288
288
}
289
289
290
+ if ( this . is_media_node ( ) ) {
291
+ const has_muted_attribute = this . attributes . some ( attr => attr . name === 'muted' ) ;
292
+
293
+ if ( has_muted_attribute ) {
294
+ return ;
295
+ }
296
+
297
+ const is_track = ( child : INode ) => child . type === 'Element' && child . name === 'track' ;
298
+ const is_caption = ( attr : Attribute ) =>
299
+ attr . name === 'kind' &&
300
+ attr . get_static_value ( ) . toString ( ) . toLowerCase ( ) === 'captions' ;
301
+ const has_captions = this . children . some (
302
+ child => ! is_track ( child ) ? false : child . attributes . some ( is_caption )
303
+ ) ;
304
+
305
+ if ( ! has_captions ) {
306
+ this . component . warn ( this , {
307
+ code : `a11y-media-has-caption` ,
308
+ message : `A11y: <${ this . name } > should have a <track> for captions`
309
+ } ) ;
310
+ }
311
+ }
312
+
290
313
this . validate_attributes ( ) ;
291
314
this . validate_special_cases ( ) ;
292
315
this . validate_bindings ( ) ;
Original file line number Diff line number Diff line change 1
- <video ><track kind =" captions" /></video >
2
- <video ></video >
3
- <video ><track /></video >
4
- <audio muted ></audio >
1
+ <video >
2
+ <track kind =" captions" />
3
+ </video >
4
+ <video />
5
+ <video >
6
+ <track />
7
+ </video >
8
+ <audio muted />
Original file line number Diff line number Diff line change 1
1
[
2
- {
3
- "code" : " a11y-media-has-caption" ,
4
- "end" : {
5
- "character" : 55 ,
6
- "column" : 15 ,
7
- "line" : 2
8
- },
9
- "message" : " A11y: Media elements must have a <track kind=\" captions\" >" ,
10
- "pos" : 40 ,
11
- "start" : {
12
- "character" : 40 ,
13
- "column" : 0 ,
14
- "line" : 2
15
- }
16
- },
17
- {
18
- "code" : " a11y-media-has-caption" ,
19
- "end" : {
20
- "character" : 80 ,
21
- "column" : 24 ,
22
- "line" : 3
23
- },
24
- "message" : " A11y: Media elements must have a <track kind=\" captions\" >" ,
25
- "pos" : 56 ,
26
- "start" : {
27
- "character" : 56 ,
28
- "column" : 0 ,
29
- "line" : 3
30
- }
31
- }
2
+ {
3
+ "code" : " a11y-media-has-caption" ,
4
+ "end" : {
5
+ "character" : 55 ,
6
+ "column" : 15 ,
7
+ "line" : 2
8
+ },
9
+ "message" : " A11y: Media elements must have a <track kind=\" captions\" >" ,
10
+ "pos" : 40 ,
11
+ "start" : {
12
+ "character" : 40 ,
13
+ "column" : 0 ,
14
+ "line" : 2
15
+ }
16
+ },
17
+ {
18
+ "code" : " a11y-media-has-caption" ,
19
+ "end" : {
20
+ "character" : 80 ,
21
+ "column" : 24 ,
22
+ "line" : 3
23
+ },
24
+ "message" : " A11y: Media elements must have a <track kind=\" captions\" >" ,
25
+ "pos" : 56 ,
26
+ "start" : {
27
+ "character" : 56 ,
28
+ "column" : 0 ,
29
+ "line" : 3
30
+ }
31
+ }
32
32
]
You can’t perform that action at this time.
0 commit comments