Skip to content

Commit

Permalink
Merge branch 'main' into plt-1763/seed-format
Browse files Browse the repository at this point in the history
  • Loading branch information
delucis authored Mar 7, 2024
2 parents b425f31 + f973aa9 commit 7f0741c
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 7 deletions.
5 changes: 0 additions & 5 deletions .changeset/good-rats-bathe.md

This file was deleted.

5 changes: 5 additions & 0 deletions .changeset/tough-moose-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro": patch
---

Fixes some false positive in the dev toolbar a11y audits, by adding the `a` element to the list of interactive elements.
14 changes: 14 additions & 0 deletions packages/astro/e2e/dev-toolbar-audits.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,18 @@ test.describe('Dev Toolbar - Audits', () => {
// Toggle app off
await appButton.click();
});

test('does not warn for non-interactive element', async ({ page, astro }) => {
await page.goto(astro.resolveUrl('/a11y-exceptions'));

const toolbar = page.locator('astro-dev-toolbar');
const appButton = toolbar.locator('button[data-app-id="astro:audit"]');
await appButton.click();

const auditCanvas = toolbar.locator('astro-dev-toolbar-app-canvas[data-app-id="astro:audit"]');
const auditHighlights = auditCanvas.locator('astro-dev-toolbar-highlight');

const count = await auditHighlights.count();
expect(count).toEqual(0);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
---


<input role="button" aria-label="Label"/>
33 changes: 32 additions & 1 deletion packages/astro/src/runtime/client/dev-toolbar/apps/audit/a11y.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,25 @@ const a11y_required_attributes = {
object: ['title', 'aria-label', 'aria-labelledby'],
};

const interactiveElements = ['button', 'details', 'embed', 'iframe', 'label', 'select', 'textarea'];
const MAYBE_INTERACTIVE = new Map([
['a', 'href'],
['input', 'type'],
['audio', 'controls'],
['img', 'usemap'],
['object', 'usemap'],
['video', 'controls'],
]);

const interactiveElements = [
'button',
'details',
'embed',
'iframe',
'label',
'select',
'textarea',
...MAYBE_INTERACTIVE.keys(),
];

const labellableElements = ['input', 'meter', 'output', 'progress', 'select', 'textarea'];

Expand Down Expand Up @@ -187,6 +205,15 @@ const ariaRoles = new Set(
)
);

function isInteractive(element: Element): boolean {
const attribute = MAYBE_INTERACTIVE.get(element.localName);
if (attribute) {
return element.hasAttribute(attribute);
}

return true;
}

export const a11y: AuditRuleWithSelector[] = [
{
code: 'a11y-accesskey',
Expand Down Expand Up @@ -434,6 +461,7 @@ export const a11y: AuditRuleWithSelector[] = [
'Interactive HTML elements like `<a>` and `<button>` cannot use non-interactive roles like `heading`, `list`, `menu`, and `toolbar`.',
selector: `[role]:is(${interactiveElements.join(',')})`,
match(element) {
if (!isInteractive(element)) return false;
const role = element.getAttribute('role');
if (!role) return false;
if (!ariaRoles.has(role)) return false;
Expand All @@ -448,6 +476,7 @@ export const a11y: AuditRuleWithSelector[] = [
'Interactive roles should not be used to convert a non-interactive element to an interactive element',
selector: `[role]:not(${interactiveElements.join(',')})`,
match(element) {
if (!isInteractive(element)) return false;
const role = element.getAttribute('role');
if (!role) return false;
if (!ariaRoles.has(role)) return false;
Expand All @@ -472,6 +501,8 @@ export const a11y: AuditRuleWithSelector[] = [
element.scrollHeight > element.clientHeight || element.scrollWidth > element.clientWidth;
if (isScrollable) return false;

if (!isInteractive(element)) return false;

if (!interactiveElements.includes(element.localName)) return true;
},
},
Expand Down
6 changes: 6 additions & 0 deletions packages/db/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @astrojs/db

## 0.6.5

### Patch Changes

- [#10350](https://github.com/withastro/astro/pull/10350) [`393ad9b2aa9fde45eb14b8b01ff3526063772452`](https://github.com/withastro/astro/commit/393ad9b2aa9fde45eb14b8b01ff3526063772452) Thanks [@Fryuni](https://github.com/Fryuni)! - Includes `./virtual.d.ts` file that was previously unpublished

## 0.6.4

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/db/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@astrojs/db",
"version": "0.6.4",
"version": "0.6.5",
"description": "",
"license": "MIT",
"type": "module",
Expand Down

0 comments on commit 7f0741c

Please sign in to comment.