Skip to content

Commit 1da598d

Browse files
committed
doc: improve accessibility of expandable lists
PR-URL: nodejs/node#56749 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com> Reviewed-By: Claudio Wunder <cwunder@gnome.org>
1 parent cfee887 commit 1da598d

File tree

4 files changed

+20
-21
lines changed

4 files changed

+20
-21
lines changed

src/generators/legacy-html/assets/api.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
function closeAllPickers() {
4444
for (const picker of pickers) {
4545
picker.parentNode.classList.remove('expanded');
46+
picker.ariaExpanded = false;
4647
}
4748

4849
window.removeEventListener('click', closeAllPickers);
@@ -60,14 +61,15 @@
6061
for (const picker of pickers) {
6162
const parentNode = picker.parentNode;
6263

64+
picker.ariaExpanded = parentNode.classList.contains('expanded');
6365
picker.addEventListener('click', function (e) {
6466
e.preventDefault();
6567

6668
/*
6769
closeAllPickers as window event trigger already closed all the pickers,
6870
if it already closed there is nothing else to do here
6971
*/
70-
if (parentNode.classList.contains('expanded')) {
72+
if (picker.ariaExpanded === 'true') {
7173
return;
7274
}
7375

@@ -77,9 +79,11 @@
7779
*/
7880

7981
requestAnimationFrame(function () {
82+
picker.ariaExpanded = true;
8083
parentNode.classList.add('expanded');
8184
window.addEventListener('click', closeAllPickers);
8285
window.addEventListener('keydown', onKeyDown);
86+
parentNode.querySelector('.picker a').focus();
8387
});
8488
});
8589
}

src/generators/legacy-html/assets/style.css

+6-11
Original file line numberDiff line numberDiff line change
@@ -203,34 +203,29 @@ li.picker-header .picker-arrow {
203203
height: 0.6rem;
204204
border-top: 0.3rem solid transparent;
205205
border-bottom: 0.3rem solid transparent;
206-
border-left: 0.6rem solid var(--color-links);
206+
border-left: 0.6rem solid currentColor;
207207
border-right: none;
208208
margin: 0 0.2rem 0.05rem 0;
209209
}
210210

211-
li.picker-header a:focus .picker-arrow,
212-
li.picker-header a:active .picker-arrow,
213-
li.picker-header a:hover .picker-arrow {
214-
border-left: 0.6rem solid var(--white);
215-
}
216-
217-
li.picker-header.expanded a:focus .picker-arrow,
218-
li.picker-header.expanded a:active .picker-arrow,
219-
li.picker-header.expanded a:hover .picker-arrow,
211+
li.picker-header.expanded .picker-arrow,
212+
:root:not(.has-js) li.picker-header:focus-within .picker-arrow,
220213
:root:not(.has-js) li.picker-header:hover .picker-arrow {
221-
border-top: 0.6rem solid var(--white);
214+
border-top: 0.6rem solid currentColor;
222215
border-bottom: none;
223216
border-left: 0.35rem solid transparent;
224217
border-right: 0.35rem solid transparent;
225218
margin-bottom: 0;
226219
}
227220

228221
li.picker-header.expanded > a,
222+
:root:not(.has-js) li.picker-header:focus-within > a,
229223
:root:not(.has-js) li.picker-header:hover > a {
230224
border-radius: 2px 2px 0 0;
231225
}
232226

233227
li.picker-header.expanded > .picker,
228+
:root:not(.has-js) li.picker-header:focus-within > .picker,
234229
:root:not(.has-js) li.picker-header:hover > .picker {
235230
display: block;
236231
z-index: 1;

src/generators/legacy-html/template.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ <h1>Node.js __VERSION__ documentation</h1>
100100
<li class="pinned-header">Node.js __VERSION__</li>
101101
__TOC_PICKER__ __GTOC_PICKER__ __ALTDOCS__
102102
<li class="picker-header">
103-
<a href="#">
103+
<a href="#options-picker" aria-controls="options-picker">
104104
<span class="picker-arrow"></span>
105105
Options
106106
</a>
107-
<div class="picker">
108-
<ul>
107+
<div class="picker" tabindex="-1">
108+
<ul id="options-picker">
109109
<li>
110110
<a href="all.html">View on single page</a>
111111
</li>

src/generators/legacy-html/utils/buildDropdowns.mjs

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ import {
2323
const buildToC = tableOfContents => {
2424
if (tableOfContents.length) {
2525
return (
26-
`<li class="picker-header"><a href="#">` +
26+
`<li class="picker-header"><a href="#toc-picker" aria-controls="toc-picker">` +
2727
`<span class="picker-arrow"></span>` +
2828
`Table of contents</a><div class="picker">` +
29-
`<div class="toc">${tableOfContents}</div></div></li>`
29+
`<div class="toc" tabindex="-1">${tableOfContents.replace('<ul', '<ul id="toc-picker"')}</div></div></li>`
3030
);
3131
}
3232

@@ -42,9 +42,9 @@ const buildToC = tableOfContents => {
4242
* @param {string} navigationContents The stringified Navigation
4343
*/
4444
const buildNavigation = navigationContents =>
45-
`<li class="picker-header"><a href="#">` +
45+
`<li class="picker-header"><a href="#gtoc-picker" aria-controls="gtoc-picker">` +
4646
`<span class="picker-arrow"></span>Index</a>` +
47-
`<div class="picker"><ul><li><a href="index.html">Index</a>` +
47+
`<div class="picker" tabindex="-1" id="gtoc-picker"><ul><li><a href="index.html">Index</a>` +
4848
`</li></ul><hr class="line" />${navigationContents}</div></li>`;
4949

5050
/**
@@ -76,9 +76,9 @@ const buildVersions = (api, added, versions) => {
7676
});
7777

7878
return (
79-
`<li class="picker-header"><a href="#">` +
79+
`<li class="picker-header"><a href="#alt-docs" aria-controls="alt-docs">` +
8080
`<span class="picker-arrow"></span>Other versions</a>` +
81-
`<div class="picker"><ol id="alt-docs">${versionsAsList.join('')}</ol></div></li>`
81+
`<div class="picker" tabindex="-1"><ol id="alt-docs">${versionsAsList.join('')}</ol></div></li>`
8282
);
8383
};
8484

0 commit comments

Comments
 (0)