Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: edge case in noInteractiveToNonInteractiveRole for <canvas>. #3728

Merged
merged 5 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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


```


Loading