Skip to content

Commit 4166fc7

Browse files
committed
a11y accordion
1 parent 931ecb9 commit 4166fc7

File tree

5 files changed

+55
-14
lines changed

5 files changed

+55
-14
lines changed

assets/css/styles.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/js/script.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
1+
function togggleBoolAttr(el, attr) {
2+
return attr == "true" ? "false" : "true";
3+
}
4+
5+
function togggleHiddenAttr(el, attr) {
6+
if (attr === true || attr === "hidden") return false;
7+
return true;
8+
}
9+
110
jQuery(document).ready(function ($) {
11+
// Accordions
12+
// accordionHeader.click(() => accordionBody where labelledby = accordionHeader.id remove hide)
13+
$(".accordion-header").click(function (event) {
14+
var $el = $(event.currentTarget);
15+
var bodyId = $el.attr("aria-controls");
16+
var $accBody = $('[id="' + bodyId + '"]');
17+
18+
// flip aria expanded
19+
$el.attr("aria-expanded", togggleBoolAttr);
20+
$accBody.attr("hidden", togggleHiddenAttr);
21+
});
22+
223
// FAQ Page
324
if ($(".page-template-template-faq").length > 0) {
425
var lock = false;

front/src/styles/base.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ body {
3535
color: $color-dark-slate-gray;
3636
}
3737

38+
button {
39+
font-family: inherit;
40+
}
41+
3842
// Responsive Font Styles
3943
// Reduce font sizes when on mobile screens
4044
// @todo: I think this should become a part of vocabulary.

front/src/styles/shame.scss

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,28 @@ span.icon {
3737

3838
// Accordion component
3939
// @todo: Should this be in vocabulary? Do/will we use this anywhere else?
40-
4140
.accordion {
4241
.accordion-item {
4342
border-bottom: 2px solid $color-light-gray;
44-
display: flex;
45-
justify-content: space-between;
46-
align-items: center;
43+
44+
.accordion-header {
45+
border: none;
46+
background-color: transparent;
47+
appearance: none;
48+
width: 100%;
49+
-webkit-appearance: none;
50+
display: flex;
51+
justify-content: space-between;
52+
align-items: center;
53+
}
4754

4855
&:hover {
4956
cursor: pointer;
5057
}
58+
59+
.accordion-body[hidden] {
60+
visibility: hidden;
61+
}
5162
}
5263
}
5364

inc/partials/home-faq.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,20 @@
1010
<h2>Frequently Asked Questions</h2>
1111
<ul class="margin-top-large margin-bottom-large accordion">
1212
<?php foreach ($faqs as $faq) : ?>
13-
<li class="margin-top-big padding-bottom-big body-big accordion-item">
14-
<p class="has-color-dark-slate-gray">
15-
<?php echo $faq['question']; ?>
16-
</p>
17-
<span class="margin-left-small icon has-text-black">
18-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -256 1792 1792" class="caret">
19-
<path fill="currentColor" d="M1426.44 407.864q0 26-19 45l-448 448q-19 19-45 19t-45-19l-448-448q-19-19-19-45t19-45q19-19 45-19h896q26 0 45 19t19 45z"/>
20-
</svg>
21-
</span>
13+
<li class="accordion-item">
14+
<button class="accordion-header padding-top-big padding-bottom-big" id="<?php echo 'accordion-'.$faq['question']; ?>" aria-expanded="false" aria-controls="<?php echo 'section-'.$faq['question']; ?>">
15+
<span class="has-color-dark-slate-gray body-big has-text-left">
16+
<?php echo $faq['question']; ?>
17+
</span>
18+
<span class="margin-left-small icon has-text-black">
19+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -256 1792 1792" class="caret">
20+
<path fill="currentColor" d="M1426.44 407.864q0 26-19 45l-448 448q-19 19-45 19t-45-19l-448-448q-19-19-19-45t19-45q19-19 45-19h896q26 0 45 19t19 45z"/>
21+
</svg>
22+
</span>
23+
</button>
24+
<div class="accordion-body accordion-body padding-left-small padding-right-small padding-bottom-normal" role="region" aria-labelledby="<?php echo 'accordion-'.$faq['question']; ?>" id="<?php echo 'section-'.$faq['question']; ?>" hidden>
25+
<?php echo $faq['answer']; ?>
26+
</div>
2227
</li>
2328
<?php endforeach; ?>
2429
</ul>

0 commit comments

Comments
 (0)