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(devtool): do not trigger interaction check for div and span #10719

Merged
merged 7 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/swift-coats-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"astro": patch
---

Fixes a false positive for the elements `div` and `span`. `div` and `span` are special elements that don't have an interaction assigned, instead it is assigned based on the role assigned via attributes.

This means that cases like the following are deemed correct by the a11y audits:
ematipico marked this conversation as resolved.
Show resolved Hide resolved

```html
<div role="tablist"></div>
<span role="button" onclick="" onkeydown=""></span>
```
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@


<input role="button" aria-label="Label"/>
<div role="grid"></div>
<span role="button" onclick="" onfocus=""></span>
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ const aria_non_interactive_roles = [
'tooltip',
];

// These elements aren't interactive and aren't non-interactive. Their interaction changes based on the role assigned to them
const roleless_elements = ['div', 'span'];
ematipico marked this conversation as resolved.
Show resolved Hide resolved

const a11y_required_content = [
// anchor-has-content
'a',
Expand Down Expand Up @@ -467,6 +470,7 @@ export const a11y: AuditRuleWithSelector[] = [
const role = element.getAttribute('role');
if (!role) return false;
if (!ariaRoles.has(role)) return false;
if (roleless_elements.includes(element.localName)) return false;

if (aria_non_interactive_roles.includes(role)) return true;
},
Expand All @@ -487,6 +491,7 @@ export const a11y: AuditRuleWithSelector[] = [
element.localName as keyof typeof a11y_non_interactive_element_to_interactive_role_exceptions
];
if (exceptions?.includes(role)) return false;
if (roleless_elements.includes(element.localName)) return false;

if (!aria_non_interactive_roles.includes(role)) return true;
},
Expand Down