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

refactor(aria): use aria metadata to find equivalent HTML element #4495

Merged
merged 2 commits into from
Nov 11, 2024

Conversation

Conaclos
Copy link
Member

@Conaclos Conaclos commented Nov 10, 2024

Summary

Part of #4241.

This PR removes the remaining role definitions from biome_aria.

I noticed some errors: we had invalid roles p and aside.
Also we had a never stabilized role associationlist. It was part of ARIA 1.2 draft and was finally removed before is stabilization. Some MDN docs still have some documentation for this role.

I refactored is_not_interactive_element to use get_implicit_role instead of traversing all roles looking for a role with the current element as concept.
This allowed me to identify some missing elements in get_implicit_role.
This also makes the code simpler to read and to understand.
I added an exception for a and area because our previous code considered them as interactive, and our current code that relies on get_implicit_role flagged them as non-interactive if href is not set.

Taking a look at the implementation of JSX A11y for interactive/non-interactive roles,
I noticed that some roles are neither interactive nor non-interactive.
This is the case of the toolbar role.
Thus, I created the AriaRole::is_non_interactive method.
In contrast to the implementation of JSX A11y, I didn't add generic because it created many regressions in our test suite.
Some of our rules have not the same test suite as JSX A11y and some of our rules have slight or subtle behavioral differences.
This makes it hard to detect if a change is expected or not.
Thus, I tried to avoid regression in our current test suite.
I think we will have to review every rule and also the implementation of JSX A11y because I noticed that there are numerous hacks and limitations in their code base.

As a side note, JSX A11y uses also the axobject-query NPM package that provides data from Chrome AXObject. This complements the data from ARIA query and is more browser-centered. We will have to investigate if we should/want to use this extra source of data to determine if an element is interactive or non-interactive.

I added std::fmt::Display impl for HtmlElementInstance. This allowed me to drastically reduce the complexity of the implementation of the useSematicElements rule.

Test Plan

@github-actions github-actions bot added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages labels Nov 10, 2024
@@ -1,22 +0,0 @@
use biome_aria_metadata::{IsoCountries, IsoLanguages, ISO_COUNTRIES, ISO_LANGUAGES};
use std::str::FromStr;

Copy link
Member Author

Choose a reason for hiding this comment

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

I moved this code in the biome_aria_metadata crate.

@Conaclos Conaclos changed the title Conaclos/aria elements refactor(aria): use aria metadata to find equivalent HTML element Nov 10, 2024
@Conaclos Conaclos requested review from a team November 10, 2024 11:27
<div role="blockquote" ></div>
<div role="associationlist" ></div>
Copy link
Member Author

Choose a reason for hiding this comment

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

The role was part of the Aria 1.2 draft and was eventually removed before the stabilization of Aria 1.2.

Comment on lines -38 to -39
<div role="p" ></div>
<div role="aside" ></div>
Copy link
Member Author

Choose a reason for hiding this comment

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

These roles don't exist.

Comment on lines -16 to -17
<div role="graphics-document" ></div>
<div role="graphics-object" ></div>
Copy link
Member Author

@Conaclos Conaclos Nov 10, 2024

Choose a reason for hiding this comment

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

Related concepts for these two roles are missing. I plan to add them back in a future PR.

Copy link

codspeed-hq bot commented Nov 10, 2024

CodSpeed Performance Report

Merging #4495 will not alter performance

Comparing conaclos/aria-elements (a823d3c) with main (95faf70)

Summary

✅ 99 untouched benchmarks

Comment on lines -10 to -13
<div role="dialog" ></div>

<div role="cell" ></div>
<div role="columnheader" ></div>
<div role="definition" ></div>
Copy link
Member Author

@Conaclos Conaclos Nov 10, 2024

Choose a reason for hiding this comment

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

Related concepts for these two roles are missing. I plan to add them back in a future PR.

@Conaclos Conaclos merged commit f38694c into main Nov 11, 2024
12 checks passed
@Conaclos Conaclos deleted the conaclos/aria-elements branch November 11, 2024 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants