Skip to content

Commit be8ed74

Browse files
zargoldbeefancohen
authored andcommitted
allowing for no <track> element (no captions) on muted audio/video
1 parent 0cbe0f1 commit be8ed74

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

__tests__/src/rules/media-has-caption-test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ ruleTester.run('media-has-caption', rule, {
4545
{
4646
code: '<video><track kind="Captions" /><track kind="subtitles" /></video>',
4747
},
48+
{
49+
code: '<audio mute={true}></audio>',
50+
},
51+
{
52+
code: '<video mute={true}></video>',
53+
},
54+
{
55+
code: '<video mute></video>',
56+
},
4857
{
4958
code: '<Audio><track kind="captions" /></Audio>',
5059
options: customSchema,
@@ -69,6 +78,22 @@ ruleTester.run('media-has-caption', rule, {
6978
code: '<Video><Track kind="captions" /></Video>',
7079
options: customSchema,
7180
},
81+
{
82+
code: '<Video mute></Video>',
83+
options: customSchema,
84+
},
85+
{
86+
code: '<Video mute={true}></Video>',
87+
options: customSchema,
88+
},
89+
{
90+
code: '<Audio mute></Audio>',
91+
options: customSchema,
92+
},
93+
{
94+
code: '<Audio mute={true}></Audio>',
95+
options: customSchema,
96+
},
7297
].map(parserOptionsMapper),
7398
invalid: [
7499
{ code: '<audio><track /></audio>', errors: [expectedError] },
@@ -82,6 +107,16 @@ ruleTester.run('media-has-caption', rule, {
82107
code: '<video><track kind="subtitles" /></video>',
83108
errors: [expectedError],
84109
},
110+
{
111+
code: '<Audio mute={false}></Audio>',
112+
options: customSchema,
113+
errors: [expectedError],
114+
},
115+
{
116+
code: '<Video mute={false}></Video>',
117+
options: customSchema,
118+
errors: [expectedError],
119+
},
85120
{ code: '<video />', errors: [expectedError] },
86121
{ code: '<audio>Foo</audio>', errors: [expectedError] },
87122
{ code: '<video>Foo</video>', errors: [expectedError] },

docs/rules/media-has-caption.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Providing captions for media is essential for deaf users to follow along. Captions should be a transcription or translation of the dialogue, sound effects, relevant musical cues, and other relevant audio information. Not only is this important for accessibility, but can also be useful for all users in the case that the media is unavailable (similar to `alt` text on an image when an image is unable to load).
44

5-
The captions should contain all important and relevant information to understand the corresponding media. This may mean that the captions are not a 1:1 mapping of the dialogue in the media content.
5+
The captions should contain all important and relevant information to understand the corresponding media. This may mean that the captions are not a 1:1 mapping of the dialogue in the media content. However, captions are *not* necessary for video components with the mute attribute.
66

77
### References
88

@@ -31,6 +31,7 @@ For the `audio`, `video`, and `track` options, these strings determine which JSX
3131
```jsx
3232
<audio><track kind="captions" {...props} /></audio>
3333
<video><track kind="captions" {...props} /></video>
34+
<video mute {...props} ></video>
3435
```
3536

3637
### Fail

src/rules/media-has-caption.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ module.exports = {
4848
if (!isMediaType(context, type)) {
4949
return;
5050
}
51-
51+
const muteProp = getProp(element.attributes, 'mute');
52+
const mutePropVal: boolean = getLiteralPropValue(muteProp);
53+
if (mutePropVal === true) {
54+
return;
55+
}
5256
// $FlowFixMe https://github.com/facebook/flow/issues/1414
5357
const trackChildren: Array<JSXElement> = node.children.filter((child: Node) => {
5458
if (child.type !== 'JSXElement') {

0 commit comments

Comments
 (0)