Skip to content

Commit 115ad01

Browse files
angelikatyborskajosevalim
authored andcommitted
Make it possibe to focus expand links in sidebar
1 parent 9065428 commit 115ad01

File tree

3 files changed

+46
-25
lines changed

3 files changed

+46
-25
lines changed

assets/css/sidebar.css

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -240,34 +240,49 @@
240240
margin-left: 10px;
241241
}
242242

243-
.sidebar #full-list li a span.icon-expand:after {
243+
.sidebar #full-list li a.expand + button.icon-expand {
244+
appearance: none;
245+
background-color: transparent;
246+
border: 0;
247+
padding: 0;
248+
cursor: pointer;
249+
color: inherit;
250+
margin-right: 10px;
251+
font-size: calc(1.2 * 16px);
252+
line-height: 20px;
253+
position: absolute;
254+
display: flex;
255+
right: 0;
256+
transform: translateY(calc(-100% - 4px));
257+
}
258+
259+
.sidebar #full-list li a + button.icon-expand:after {
244260
font-family: remixicon;
245261
font-style: normal;
246262
-webkit-font-smoothing: antialiased;
247263
-moz-osx-font-smoothing: grayscale;
248264
}
249265

250-
.sidebar #full-list li a.expand > span.icon-expand:after {
266+
.sidebar #full-list li a.expand + button.icon-expand:after {
251267
content: var(--icon-arrow-down-s);
252-
margin-right: 10px;
253-
font-size: 1.2em;
254-
position: absolute;
255-
right: 0;
256268
}
257269

258-
.sidebar #full-list li.open > a.expand > span.icon-expand:after {
270+
.sidebar #full-list li.open > a.expand + button.icon-expand:after {
259271
content: var(--icon-arrow-up-s);
260272
}
261273

262-
.sidebar #full-list li.docs > a > span.icon-expand:after {
274+
.sidebar #full-list li.docs > a + button.icon-expand {
263275
margin-right: 12px;
276+
font-size: calc(1 * 16px);
277+
line-height: 1;
278+
transform: translateY(calc(-100% - 5px));
279+
}
280+
281+
.sidebar #full-list li.docs > a + button.icon-expand:after {
264282
content: var(--icon-add);
265-
font-size: 1em;
266-
position: absolute;
267-
right: 0;
268283
}
269284

270-
.sidebar #full-list li.docs.open > a > span.icon-expand:after {
285+
.sidebar #full-list li.docs.open > a + button.icon-expand:after {
271286
content: var(--icon-subtract);
272287
}
273288

@@ -305,6 +320,10 @@
305320
color: var(--sidebarActiveItem);
306321
}
307322

323+
.sidebar #full-list li .current-section > a + button.icon-expand {
324+
color: var(--sidebarActiveItem);
325+
}
326+
308327
.sidebar #full-list > li > a:hover {
309328
border-left: 3px solid var(--sidebarLanguageAccentBar);
310329
padding-left: 12px;

assets/js/handlebars/templates/sidebar-items.handlebars

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
{{else}}
1717
{{{node.title}}}
1818
{{/if}}
19-
{{#isEmptyArray node.headers}}
20-
{{else}}
21-
<span class="icon-expand"></span>
22-
{{/isEmptyArray}}
2319
</a>
2420

21+
{{#isEmptyArray node.headers}}
22+
{{else}}
23+
<button class="icon-expand" aria-label="expand"></button>
24+
{{/isEmptyArray}}
25+
2526
{{#isArray node.headers}}
2627
{{#isNonEmptyArray node.headers}}
2728
<ul>
@@ -38,8 +39,8 @@
3839
<li class="docs {{#isLocal node.id}}open{{/isLocal}}">
3940
<a href="{{node.id}}.html#content" class="expand">
4041
Sections
41-
<span class="icon-expand"></span>
4242
</a>
43+
<button class="icon-expand" aria-label="expand"></button>
4344
<ul class="sections-list deflist">
4445
{{#each sections}}
4546
<li>
@@ -58,8 +59,8 @@
5859
<li class="docs">
5960
<a href="{{node.id}}.html#{{group.key}}" class="expand">
6061
{{group.name}}
61-
<span class="icon-expand"></span>
6262
</a>
63+
<button class="icon-expand" aria-label="expand"></button>
6364
<ul class="{{group.key}}-list deflist">
6465
{{#each group.nodes}}
6566
<li>

assets/js/sidebar/sidebar-list.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,20 @@ function renderSidebarNodeList (nodesByType, type) {
5555
})
5656

5757
// Register event listeners
58+
nodeList.querySelectorAll('li a + button').forEach(button => {
59+
button.addEventListener('click', event => {
60+
const target = event.target
61+
const listItem = target.closest('li')
62+
listItem.classList.toggle('open')
63+
})
64+
})
65+
5866
nodeList.querySelectorAll('li a').forEach(anchor => {
5967
anchor.addEventListener('click', event => {
6068
const target = event.target
6169
const listItem = target.closest('li')
6270
const previousSection = nodeList.querySelector('.current-section')
6371

64-
// Expand icon should not navigate
65-
if (target.matches('.icon-expand')) {
66-
event.preventDefault()
67-
listItem.classList.toggle('open')
68-
return
69-
}
70-
7172
// Clear the previous current section
7273
if (previousSection) {
7374
previousSection.classList.remove('current-section')

0 commit comments

Comments
 (0)