Skip to content

Commit 7aff4c1

Browse files
fix(lint): ignore custom elements in noInteractiveElementToNoninteractiveRole (#10766)
1 parent 575ced6 commit 7aff4c1

4 files changed

Lines changed: 32 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Fixed [#2862](https://github.com/biomejs/biome/issues/2862): [`noInteractiveElementToNoninteractiveRole`](https://biomejs.dev/linter/rules/no-interactive-element-to-noninteractive-role/) no longer reports custom elements (a tag name containing a dash, e.g. `<my-button role="img" />`). Per the [W3C HTML-ARIA specification](https://www.w3.org/TR/html-aria/#el-autonomous-custom-element), a custom element may be given any role or none.

crates/biome_js_analyze/src/lint/a11y/no_interactive_element_to_noninteractive_role.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ declare_lint_rule! {
3838
/// <canvas role="img" />;
3939
/// ```
4040
///
41+
/// Custom elements (a tag name containing a dash) may be given any role or none:
42+
///
43+
/// ```jsx
44+
/// <>
45+
/// <my-button role="img" />
46+
/// </>;
47+
/// ```
48+
///
4149
pub NoInteractiveElementToNoninteractiveRole {
4250
version: "1.3.0",
4351
name: "noInteractiveElementToNoninteractiveRole",
@@ -60,6 +68,11 @@ impl Rule for NoInteractiveElementToNoninteractiveRole {
6068
if !node.is_element() {
6169
return None;
6270
}
71+
72+
if node.is_custom_element() {
73+
return None;
74+
}
75+
6376
let role_attribute = node.find_attribute_by_name("role")?;
6477
let role_attribute_static_value = role_attribute.as_static_value()?;
6578
let role_attribute_value = role_attribute_static_value.text();

crates/biome_js_analyze/tests/specs/a11y/noInteractiveElementToNoninteractiveRole/valid.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,4 +276,10 @@
276276
src={'/assets/head.png'}
277277
alt='An ASCII-style headshot'
278278
/>
279-
</picture>
279+
</picture>;
280+
/* Custom elements can have any role or none (https://www.w3.org/TR/html-aria/#el-autonomous-custom-element) */
281+
<>
282+
<my-button role="img" />
283+
<my-element role="listitem" />
284+
<custom-card role="button" />
285+
</>;

crates/biome_js_analyze/tests/specs/a11y/noInteractiveElementToNoninteractiveRole/valid.jsx.snap

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,12 @@ expression: valid.jsx
282282
src={'/assets/head.png'}
283283
alt='An ASCII-style headshot'
284284
/>
285-
</picture>
285+
</picture>;
286+
/* Custom elements can have any role or none (https://www.w3.org/TR/html-aria/#el-autonomous-custom-element) */
287+
<>
288+
<my-button role="img" />
289+
<my-element role="listitem" />
290+
<custom-card role="button" />
291+
</>;
286292
287293
```

0 commit comments

Comments
 (0)