Skip to content

Commit 7d83cd3

Browse files
fix(lint): ignore custom elements in noInteractiveElementToNoninteractiveRole
Fixes #2862. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 6df1534 commit 7d83cd3

4 files changed

Lines changed: 32 additions & 0 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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,9 @@
277277
alt='An ASCII-style headshot'
278278
/>
279279
</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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,5 +283,13 @@ expression: valid.jsx
283283
alt='An ASCII-style headshot'
284284
/>
285285
</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
```
294+
295+
_Note: The parser emitted 4 diagnostics which are not shown here._

0 commit comments

Comments
 (0)