Skip to content

Commit

Permalink
fix: edge case in noInteractiveToNonInteractiveRole for <canvas>. (
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyshew committed Aug 28, 2024
1 parent 2d590ea commit 102ceeb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

- Fix JSX expressions for `noAriaHiddenOnFocusable` ([#3708](https://github.com/biomejs/biome/pull/3708)) . Contributed by @anthonyshew

- Fix edge case for `<canvas>` elements that use `role="img"` ([#3728](https://github.com/biomejs/biome/pull/3728)) . Contributed by @anthonyshew

- Fix [#3633](https://github.com/biomejs/biome/issues/3633), where diagnostics where incorrectly printed if the code has errors. Contributed by @ematipico

### Configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ declare_lint_rule! {
/// <input role="button" />;
/// ```
///
/// ```jsx
/// <canvas role="img" />;
/// ```
///
pub NoInteractiveElementToNoninteractiveRole {
version: "1.3.0",
name: "noInteractiveElementToNoninteractiveRole",
Expand Down Expand Up @@ -69,6 +73,11 @@ impl Rule for NoInteractiveElementToNoninteractiveRole {
return None;
}

// A <canvas> element can be given an "img" to make it non-interactive for a11y reasons.
if element_name.text_trimmed() == "canvas" && role_attribute_value == "img" {
return None;
}

// a tag without href is considered non-interactive
if element_name.text_trimmed() == "a"
&& node.find_attribute_by_name("href").is_none()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<body role="button" />;
<br role="button" />;
<canvas role="button" />;
<canvas role="img" />;
<caption role="button" />;
<center role="button" />;
<cite role="button" />;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: crates/biome_js_analyze/tests/spec_tests.rs
assertion_line: 86
expression: valid.jsx
---
# Input
Expand Down Expand Up @@ -61,6 +62,7 @@ expression: valid.jsx
<body role="button" />;
<br role="button" />;
<canvas role="button" />;
<canvas role="img" />;
<caption role="button" />;
<center role="button" />;
<cite role="button" />;
Expand Down Expand Up @@ -272,5 +274,3 @@ expression: valid.jsx


```


0 comments on commit 102ceeb

Please sign in to comment.