File tree Expand file tree Collapse file tree 5 files changed +55
-14
lines changed Expand file tree Collapse file tree 5 files changed +55
-14
lines changed Original file line number Diff line number Diff line change
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
+
1
10
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
+
2
23
// FAQ Page
3
24
if ( $ ( ".page-template-template-faq" ) . length > 0 ) {
4
25
var lock = false ;
Original file line number Diff line number Diff line change @@ -35,6 +35,10 @@ body {
35
35
color : $color-dark-slate-gray ;
36
36
}
37
37
38
+ button {
39
+ font-family : inherit ;
40
+ }
41
+
38
42
// Responsive Font Styles
39
43
// Reduce font sizes when on mobile screens
40
44
// @todo: I think this should become a part of vocabulary.
Original file line number Diff line number Diff line change @@ -37,17 +37,28 @@ span.icon {
37
37
38
38
// Accordion component
39
39
// @todo: Should this be in vocabulary? Do/will we use this anywhere else?
40
-
41
40
.accordion {
42
41
.accordion-item {
43
42
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
+ }
47
54
48
55
& :hover {
49
56
cursor : pointer ;
50
57
}
58
+
59
+ .accordion-body [hidden ] {
60
+ visibility : hidden ;
61
+ }
51
62
}
52
63
}
53
64
Original file line number Diff line number Diff line change 10
10
<h2>Frequently Asked Questions</h2>
11
11
<ul class="margin-top-large margin-bottom-large accordion">
12
12
<?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>
22
27
</li>
23
28
<?php endforeach ; ?>
24
29
</ul>
You can’t perform that action at this time.
0 commit comments