Skip to content

Commit eaaf49c

Browse files
authored
fix(lint-page): add accessible labels to filters (#17434)
## Summary Fix 4 WAVE accessibility errors on the Clippy lints page (#15604). The `theme-choice` <select> and three version-filter <input> elements had no programmatically associated labels, making them unidentifiable to screen readers. ## Changes - `util/gh-pages/index_template.html:34` — changed `<div class="setting-radio-name">` to `<label class="setting-radio-name" for="theme-choice">` to associate the visible "Theme" text with the select element - `util/gh-pages/index_template.html:121-123` — added `for="version-filter-{{ name }}"` on each version label and `id="version-filter-{{ name }}"` on each version input, producing three pairings: version-filter-gte, version-filter-lte, version-filter-eq - `tests/lint-page.rs` (new) — regression test asserting all four label associations exist in the template ## Not in scope Colors, contrast, CSS, JavaScript, and lint logic are untouched. ## Convention Uses `<label for="">`, the same pattern already established in the template for the search input (line 155). ## Test cargo test --test lint-page — 1 passed, 0 failed. changelog: Fix accessible labels for the theme and version filters on the lint page Part of #15604
2 parents 3f4c5f5 + 120e493 commit eaaf49c

2 files changed

Lines changed: 37 additions & 3 deletions

File tree

tests/lint-page.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// This test checks that the lint list page stays accessible: the controls must
2+
// keep the `<label for="...">`/`id="..."` pairings that screen readers use to
3+
// name them. Without those the theme selector and the version filters are
4+
// announced as unnamed widgets, which was four of the WAVE errors in #15604.
5+
//
6+
// The check is only a plain text search over the template, so it does not
7+
// verify that an `id` landed on the right element. That is a known limitation,
8+
// not a reason to drop the test: the pairings are easy to lose when the markup
9+
// is reshuffled and nothing else in CI catches it. Do not remove or loosen
10+
// these assertions to get an unrelated change to
11+
// `util/gh-pages/index_template.html` through. Once the GUI test suite (#15634)
12+
// lands this can be replaced by a check against the rendered page.
13+
14+
#[test]
15+
fn lint_page_accessibility() {
16+
let template = include_str!("../util/gh-pages/index_template.html");
17+
18+
// The theme selector must have a programmatically associated label
19+
assert!(
20+
template.contains(r#"for="theme-choice""#),
21+
"theme-choice <select> is missing an associated <label>",
22+
);
23+
24+
// The version-filter inputs are generated via a template loop.
25+
// Each input must carry an id and its sibling <label> a matching `for`.
26+
assert!(
27+
template.contains(r#"id="version-filter-{{ name }}""#),
28+
"version-filter inputs are missing id=\"version-filter-...\"",
29+
);
30+
assert!(
31+
template.contains(r#"for="version-filter-{{ name }}""#),
32+
"version-filter inputs are missing an associated <label for=\"version-filter-...\">",
33+
);
34+
}

util/gh-pages/index_template.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<div id="settings-dropdown" class="dropdown"> {# #}
3232
<button class="settings-icon" tabindex="-1"></button> {# #}
3333
<div class="settings-menu" tabindex="-1"> {# #}
34-
<div class="setting-radio-name">Theme</div> {# #}
34+
<label class="setting-radio-name" for="theme-choice">Theme</label> {# #}
3535
<select id="theme-choice"> {# #}
3636
<option value="ayu">Ayu</option> {# #}
3737
<option value="coal">Coal</option> {# #}
@@ -118,9 +118,9 @@ <h1 class="page-header">Clippy Lints <span class="badge">Total number: {{+ count
118118
<li role="separator" class="divider"></li> {# #}
119119
{% for (sym, name) in [("≥", "gte"), ("≤", "lte"), ("=", "eq")] %}
120120
<li class="checkbox"> {# #}
121-
<label>{{ sym }}</label> {#+ #}
121+
<label for="version-filter-{{ name }}">{{ sym }}</label> {#+ #}
122122
<span>1.</span> {# #}
123-
<input type="number" name="{{ name }}" min="29" maxlength="2" class="version-filter-input form-control filter-input" /> {# #}
123+
<input id="version-filter-{{ name }}" type="number" name="{{ name }}" min="29" maxlength="2" class="version-filter-input form-control filter-input" /> {# #}
124124
<span>.0</span> {# #}
125125
</li> {# #}
126126
{% endfor %}

0 commit comments

Comments
 (0)