Skip to content

Commit da3be4f

Browse files
committed
Make table of content an accessible expandable button
1 parent d5a219d commit da3be4f

3 files changed

Lines changed: 13 additions & 6 deletions

File tree

_layouts/article.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ <h1 class="h0-mktg lh-condensed text-center mb-3">{{ page.title }}</h1>
1111
<p class="lead text-center text-gray col-md-8 mx-auto mb-4 position-relative">{{ page.description }}</p>
1212
<nav class="toc mb-4 mb-md-6">
1313
<div class="Box col-sm-8 col-md-4 col-lg-3 mx-auto">
14-
<a class="toc-trigger d-block text-center p-3">
14+
<button type="button" class="toc-trigger d-block text-center p-3" aria-expanded="false" aria-controls="toc-list">
1515
<span class="text-black">{{ t.article.table_of_contents }}</span><svg height="18"
1616
class="octicon octicon-triangle-down ml-2 fill-blue v-align-middle icon-flip" viewBox="0 0 12 16"
17-
version="1.1" width="13" role="img">
17+
version="1.1" width="13" aria-hidden="true" focusable="false">
1818
<path fill-rule="evenodd" d="M0 5l6 6 6-6z"></path>
1919
</svg>
20-
</a>
21-
{% include jekyll-toc.html html=content h_max=2 ordered=true class="toc-list list-style-none"
20+
</button>
21+
{% include jekyll-toc.html html=content h_max=2 ordered=true id="toc-list" class="toc-list list-style-none"
2222
item_class="border-top" anchor_class="d-block py-3 px-3" %}
2323
</div>
2424
</nav>

assets/css/toc.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
}
99

1010
.toc-trigger {
11+
width: 100%;
12+
background: transparent;
13+
border: 0;
14+
font: inherit;
15+
color: inherit;
16+
1117
&:hover {
1218
text-decoration: none;
1319
cursor: pointer;

assets/js/toc.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
$(function() {
22
$(document).click(function() {
33
// Hiding ToC
4-
$('.toc-trigger').removeClass('toc-open');
4+
$('.toc-trigger').removeClass('toc-open').attr('aria-expanded', 'false');
55
$('.toc-list').removeClass('is-shown');
66
});
77

@@ -10,7 +10,8 @@ $(function() {
1010
// Prevent bubbling event for proper hiding
1111
e.stopPropagation();
1212
// Calling a function in case you want to expand upon this.
13-
$(this).toggleClass('toc-open');
13+
var $trigger = $(this).toggleClass('toc-open');
14+
$trigger.attr('aria-expanded', $trigger.hasClass('toc-open') ? 'true' : 'false');
1415
$('.toc-list').toggleClass('is-shown');
1516
});
1617
});

0 commit comments

Comments
 (0)