Skip to content

Commit 6d3fb6f

Browse files
authored
chore: port changes from node core
1 parent cfee887 commit 6d3fb6f

File tree

4 files changed

+32
-42
lines changed

4 files changed

+32
-42
lines changed

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

Lines changed: 5 additions & 1 deletion
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

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ code,
137137
.pre,
138138
span.type,
139139
a.type {
140-
font-family: SFMono-Regular, Menlo, Consolas, 'Liberation Mono', 'Courier New',
141-
monospace;
140+
font-family: SFMono-Regular, Menlo, Consolas, 'Liberation Mono',
141+
'Courier New', monospace;
142142
font-size: 0.9em;
143143
}
144144

@@ -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;
@@ -592,35 +587,26 @@ hr {
592587
margin: 0;
593588
}
594589

595-
.toc li a::before {
596-
content: '■';
597-
color: var(--color-text-primary);
598-
padding-right: 1em;
599-
font-size: 0.9em;
600-
}
601-
602-
.toc li a:hover::before {
603-
color: var(--white);
604-
}
605-
606-
.toc ul ul a {
607-
padding-left: 1rem;
590+
.toc > ul:first-child {
591+
margin-left: 1rem;
608592
}
609593

610-
.toc ul ul ul a {
611-
padding-left: 2rem;
594+
.toc li {
595+
display: list-item;
596+
list-style: square;
612597
}
613598

614-
.toc ul ul ul ul a {
615-
padding-left: 3rem;
599+
.toc li a {
600+
display: inline;
601+
padding-left: 0;
616602
}
617603

618-
.toc ul ul ul ul ul a {
619-
padding-left: 4rem;
604+
.toc li a:hover::before {
605+
color: var(--white);
620606
}
621607

622-
.toc ul ul ul ul ul ul a {
623-
padding-left: 5rem;
608+
.toc ul {
609+
padding-left: 1rem;
624610
}
625611

626612
#toc .stability_0::after,

src/generators/legacy-html/template.html

Lines changed: 3 additions & 3 deletions
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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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"><ul id="gtoc-picker"><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)