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: let aria-label be valid for useHeadingContent. #3767

Merged
merged 4 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 4 additions & 2 deletions CHANGELOG.md
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just taking the opportunity to remove whitespaces I left in my other fix lines. 😄

Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,14 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

- Migrating from Prettier or ESLint no longer overwrite the `overrides` field from the configuration ([#3544](https://github.com/biomejs/biome/issues/3544)). Contributed by @Conaclos

- Fix JSX expressions for `noAriaHiddenOnFocusable` ([#3708](https://github.com/biomejs/biome/pull/3708)) . Contributed by @anthonyshew
- 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 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

- Allow `aria-label` on heading to prevent `useHeadingContent` diagnostic ([#3767](https://github.com/biomejs/biome/pull/3767)). Contributed by @anthonyshew

### Configuration

- Add support for loading configuration from `.editorconfig` files ([#1724](https://github.com/biomejs/biome/issues/1724)).
Expand Down
8 changes: 8 additions & 0 deletions crates/biome_js_analyze/src/lint/a11y/use_heading_content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ declare_lint_rule! {
/// ```
///
/// ```jsx
/// <h1 aria-label="Screen reader content"><div aria-hidden="true">invisible content</div></h1>
/// ```
///
/// ```jsx
/// <h1 dangerouslySetInnerHTML={{ __html: "heading" }} />
/// ```
///
Expand Down Expand Up @@ -68,6 +72,10 @@ impl Rule for UseHeadingContent {
let name = node.name().ok()?.name_value_token()?;

if HEADING_ELEMENTS.contains(&name.text_trimmed()) {
if node.has_truthy_attribute("aria-label") {
return None;
}

if node.has_truthy_attribute("aria-hidden") {
return Some(());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<div aria-hidden />
visible content
</h1>
<h1 aria-label="Screen reader content"><div aria-hidden="true">invisible content</div></h1>
<h1 dangerouslySetInnerHTML={{ __html: "heading" }}></h1>
<h1 children={children} />
<h1 children={"heading"} />
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 @@ -40,6 +41,7 @@ expression: valid.jsx
<div aria-hidden />
visible content
</h1>
<h1 aria-label="Screen reader content"><div aria-hidden="true">invisible content</div></h1>
<h1 dangerouslySetInnerHTML={{ __html: "heading" }}></h1>
<h1 children={children} />
<h1 children={"heading"} />
Expand All @@ -55,5 +57,3 @@ expression: valid.jsx
</>;

```


Loading