Skip to content

Commit 8d2c75f

Browse files
authored
Merge pull request #14834 from nextcloud/fix/bitv-9739-search-label
fix(a11y): add visible label and search icon to search input
2 parents 9a49019 + 7915f38 commit 8d2c75f

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

_shared_assets/static/custom.css

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,40 @@ h6 {
1212
font-family: system-ui, -apple-system, "Segoe UI", Roboto, Oxygen-Sans, Cantarell, Ubuntu, "Helvetica Neue", "Noto Sans", "Liberation Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
1313
}
1414

15+
/* Visually hidden utility — element stays in the accessibility tree
16+
but is not visible on screen. Satisfies WCAG 3.3.2 / BITV 9.3.3.2
17+
for the search form label. */
18+
.sr-only {
19+
position: absolute;
20+
width: 1px;
21+
height: 1px;
22+
padding: 0;
23+
margin: -1px;
24+
overflow: hidden;
25+
clip: rect(0, 0, 0, 0);
26+
white-space: nowrap;
27+
border: 0;
28+
}
29+
30+
/* Search input wrapper — positions the magnifying-glass icon inside
31+
the input so sighted users can identify the field without a label. */
32+
.wy-form-search {
33+
position: relative;
34+
}
35+
36+
.wy-form-search-icon {
37+
position: absolute;
38+
top: 50%;
39+
left: 10px;
40+
transform: translateY(-50%);
41+
color: #555;
42+
pointer-events: none;
43+
}
44+
45+
.wy-form-search input[type="text"] {
46+
padding-left: 30px;
47+
}
48+
1549
/* NC blue */
1650
.wy-side-nav-search {
1751
background-color: #0082c9;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{%- if 'singlehtml' not in builder %}
2+
{#
3+
Custom searchbox override.
4+
5+
RTD's default searchbox has an aria-label but no visible label and no
6+
search symbol, which fails WCAG 3.3.2 / BITV 9.3.3.2 (inputs must
7+
have a visible label or identifying symbol).
8+
9+
Changes from the upstream template:
10+
- add an explicit <label> element (visually hidden via .sr-only, still
11+
announced by screen readers as an accessible name)
12+
- add a FontAwesome magnifying-glass icon that gives sighted users a
13+
visual cue that this is a search field
14+
#}
15+
<div role="search">
16+
<form id="rtd-search-form" class="wy-form" action="{{ pathto('search') }}" method="get">
17+
<label for="rtd-search-input" class="sr-only">{{ _('Search docs') }}</label>
18+
<div class="wy-form-search">
19+
<span class="fa fa-search wy-form-search-icon" aria-hidden="true"></span>
20+
<input id="rtd-search-input"
21+
type="text"
22+
name="q"
23+
placeholder="{{ _('Search docs') }}"
24+
aria-label="{{ _('Search docs') }}" />
25+
</div>
26+
<input type="hidden" name="check_keywords" value="yes" />
27+
<input type="hidden" name="area" value="default" />
28+
</form>
29+
</div>
30+
{%- endif %}

0 commit comments

Comments
 (0)