Skip to content

Commit 79ffa5d

Browse files
authoredOct 14, 2024··
fix(dev-toolbar): false positive in Audit with a11y check on labels (#12223)
* fix(dev-toolbar): false positive in Audit with a11y check on labels * test: add e2e test for a11y audit on labelable elements * docs: complete changeset to explain why this is a problem
1 parent fb55695 commit 79ffa5d

File tree

4 files changed

+76
-1
lines changed

4 files changed

+76
-1
lines changed
 

‎.changeset/selfish-toes-carry.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Fixes a false positive reported by the dev toolbar Audit app where a label was considered missing when associated with a button
6+
7+
The `button` element can be [used with a label](https://www.w3.org/TR/2011/WD-html5-author-20110809/forms.html#category-label) (e.g. to create a switch) and should not be reported as an accessibility issue when used as a child of a `label`.

‎packages/astro/e2e/dev-toolbar-audits.test.js

+14
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,18 @@ test.describe('Dev Toolbar - Audits', () => {
170170
const count = await auditHighlights.count();
171171
expect(count).toEqual(0);
172172
});
173+
174+
test('does not warn about label with valid labelable elements', async ({ page, astro }) => {
175+
await page.goto(astro.resolveUrl('/a11y-labelable'));
176+
177+
const toolbar = page.locator('astro-dev-toolbar');
178+
const appButton = toolbar.locator('button[data-app-id="astro:audit"]');
179+
await appButton.click();
180+
181+
const auditCanvas = toolbar.locator('astro-dev-toolbar-app-canvas[data-app-id="astro:audit"]');
182+
const auditHighlights = auditCanvas.locator('astro-dev-toolbar-highlight');
183+
184+
const count = await auditHighlights.count();
185+
expect(count).toEqual(0);
186+
});
173187
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
3+
---
4+
5+
<label for="button1">Button label</label>
6+
<button id="button1" />
7+
<label>
8+
Button label as child
9+
<button>Activate?</button>
10+
</label>
11+
<label for="input1">Input label</label>
12+
<input id="input1" />
13+
<label>
14+
Input label as child
15+
<input type="text" />
16+
</label>
17+
<label for="meter1">Meter label</label>
18+
<meter id="meter1" min="0" max="100" value="75">75%</meter>
19+
<label>
20+
Meter label as child
21+
<meter min="0" max="100" value="75">75%</meter>
22+
</label>
23+
<label for="output1">Output label</label>
24+
<output id="output1">"Hello, world!"</output>
25+
<label>
26+
Output label as child
27+
<output>"Hello, world!"</output>
28+
</label>
29+
<label for="progress1">Progress label</label>
30+
<progress id="progress1" max="100" value="70">70%</progress>
31+
<label>
32+
Progress label as child
33+
<progress max="100" value="70">70%</progress>
34+
</label>
35+
<label for="select1">Select label</label>
36+
<select id="select1">
37+
<option>Option 1</option>
38+
<option>Option 2</option>
39+
<option>Option 3</option>
40+
</select>
41+
<label>
42+
Select label as child
43+
<select>
44+
<option>Option 1</option>
45+
<option>Option 2</option>
46+
<option>Option 3</option>
47+
</select>
48+
</label>
49+
<label for="textarea1">Textarea label</label>
50+
<textarea cols="33" id="textarea1" rows="5" />
51+
<label>
52+
Textarea label as child
53+
<textarea cols="33" rows="5" />
54+
</label>

‎packages/astro/src/runtime/client/dev-toolbar/apps/audit/rules/a11y.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const interactiveElements = [
6262
...MAYBE_INTERACTIVE.keys(),
6363
];
6464

65-
const labellableElements = ['input', 'meter', 'output', 'progress', 'select', 'textarea'];
65+
const labellableElements = ['button', 'input', 'meter', 'output', 'progress', 'select', 'textarea'];
6666

6767
const aria_non_interactive_roles = [
6868
'alert',

0 commit comments

Comments
 (0)
Please sign in to comment.