Skip to content

Commit 3559997

Browse files
authored
feat: implement a11y aria-activedescendant-has-tabindex (#8172)
#820
1 parent a71b8b9 commit 3559997

File tree

5 files changed

+55
-0
lines changed

5 files changed

+55
-0
lines changed

site/content/docs/06-accessibility-warnings.md

+12
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ Enforce no `accesskey` on element. Access keys are HTML attributes that allow we
1919

2020
---
2121

22+
### `a11y-aria-activedescendant-has-tabindex`
23+
24+
An element with `aria-activedescendant` must be tabbable, so it must either have an inherent `tabindex` or declare `tabindex` as an attribute.
25+
26+
```sv
27+
<!-- A11y: Elements with attribute aria-activedescendant should have tabindex value -->
28+
<div aria-activedescendant="some-id" />
29+
30+
```
31+
32+
---
33+
2234
### `a11y-aria-attributes`
2335

2436
Certain reserved DOM elements do not support ARIA roles, states and properties. This is often because they are not visible, for example `meta`, `html`, `script`, `style`. This rule enforces that these DOM elements do not contain the `aria-*` props.

src/compiler/compile/compiler_warnings.ts

+4
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ export default {
187187
code: 'a11y-no-noninteractive-tabindex',
188188
message: 'A11y: noninteractive element cannot have nonnegative tabIndex value'
189189
},
190+
a11y_aria_activedescendant_has_tabindex: {
191+
code: 'a11y-aria-activedescendant-has-tabindex',
192+
message: 'A11y: Elements with attribute aria-activedescendant should have tabindex value'
193+
},
190194
redundant_event_modifier_for_touch: {
191195
code: 'redundant-event-modifier',
192196
message: 'Touch event handlers that don\'t use the \'event\' object are passive by default'

src/compiler/compile/nodes/Element.ts

+5
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,11 @@ export default class Element extends Node {
484484
component.warn(attribute, compiler_warnings.a11y_incorrect_attribute_type(schema, name));
485485
}
486486
}
487+
488+
// aria-activedescendant-has-tabindex
489+
if (name === 'aria-activedescendant' && !is_interactive_element(this.name, attribute_map) && !attribute_map.has('tabindex')) {
490+
component.warn(attribute, compiler_warnings.a11y_aria_activedescendant_has_tabindex);
491+
}
487492
}
488493

489494
// aria-role
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!-- VALID -->
2+
<input />
3+
<input tabindex="0" />
4+
<input aria-activedescendant="some-id" />
5+
<input aria-activedescendant="some-id" tabindex={0} />
6+
<input aria-activedescendant="some-id" tabindex={1} />
7+
<input aria-activedescendant="some-id" tabindex="0" />
8+
<input aria-activedescendant="some-id" tabindex={-1} />
9+
<input aria-activedescendant="some-id" tabindex="-1" />
10+
11+
<div />
12+
<div aria-activedescendant="some-id" role="tablist" tabindex={-1} />
13+
<div aria-activedescendant="some-id" role="tablist" tabindex="-1" />
14+
15+
<!-- INVALID -->
16+
<div aria-activedescendant="some-id" />
17+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[
2+
{
3+
"code": "a11y-aria-activedescendant-has-tabindex",
4+
"end": {
5+
"character": 568,
6+
"column": 36,
7+
"line": 16
8+
},
9+
"message": "A11y: Elements with attribute aria-activedescendant should have tabindex value",
10+
"pos": 537,
11+
"start": {
12+
"character": 537,
13+
"column": 5,
14+
"line": 16
15+
}
16+
}
17+
]

0 commit comments

Comments
 (0)