Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve accordion accessibility #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions dist/spectre.css
Original file line number Diff line number Diff line change
Expand Up @@ -1963,6 +1963,10 @@ video.video-responsive::before {
text-decoration: none;
}

.accordion [type=radio]:focus + label,
.accordion [type=checkbox]:focus + label {
box-shadow: 0 0 0 .1rem rgba(87, 85, 217, .2);
}
.accordion input:checked ~ .accordion-header > .icon:first-child,
.accordion[open] .accordion-header > .icon:first-child {
transform: rotate(90deg);
Expand Down
2 changes: 1 addition & 1 deletion dist/spectre.min.css

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions docs/components/accordions.html
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ <h3 class="s-title">Accordions<a class="anchor" href="#accordions" aria-hidden="
<div class="docs-demo columns">
<div class="column col-6 col-md-12">
<div class="accordion">
<input id="accordion-1" type="radio" name="accordion-radio" hidden="" checked="">
<input class="text-assistive" id="accordion-1" type="radio" name="accordion-radio" checked="">
<label class="accordion-header c-hand" for="accordion-1"><i class="icon icon-arrow-right mr-1"></i>Elements</label>
<div class="accordion-body">
<ul class="menu menu-nav">
Expand All @@ -214,7 +214,7 @@ <h3 class="s-title">Accordions<a class="anchor" href="#accordions" aria-hidden="
</div>
</div>
<div class="accordion">
<input id="accordion-2" type="radio" name="accordion-radio" hidden="">
<input class="text-assistive" id="accordion-2" type="radio" name="accordion-radio">
<label class="accordion-header c-hand" for="accordion-2"><i class="icon icon-arrow-right mr-1"></i>Layout</label>
<div class="accordion-body">
<ul class="menu menu-nav">
Expand All @@ -224,7 +224,7 @@ <h3 class="s-title">Accordions<a class="anchor" href="#accordions" aria-hidden="
</div>
</div>
<div class="accordion">
<input id="accordion-3" type="radio" name="accordion-radio" hidden="">
<input class="text-assistive" id="accordion-3" type="radio" name="accordion-radio">
<label class="accordion-header c-hand" for="accordion-3"><i class="icon icon-arrow-right mr-1"></i>Components</label>
<div class="accordion-body">
<ul class="menu menu-nav">
Expand All @@ -236,7 +236,7 @@ <h3 class="s-title">Accordions<a class="anchor" href="#accordions" aria-hidden="
</div>
<div class="column col-6 col-md-12">
<div class="accordion">
<input id="accordion-4" type="checkbox" name="accordion-checkbox" hidden="" checked="">
<input class="text-assistive" id="accordion-4" type="checkbox" name="accordion-checkbox" checked="">
<label class="accordion-header c-hand" for="accordion-4">Elements</label>
<div class="accordion-body">
<ul class="menu menu-nav">
Expand All @@ -246,7 +246,7 @@ <h3 class="s-title">Accordions<a class="anchor" href="#accordions" aria-hidden="
</div>
</div>
<div class="accordion">
<input id="accordion-5" type="checkbox" name="accordion-checkbox" hidden="">
<input class="text-assistive" id="accordion-5" type="checkbox" name="accordion-checkbox">
<label class="accordion-header c-hand" for="accordion-5">Layout</label>
<div class="accordion-body">
<ul class="menu menu-nav">
Expand All @@ -256,7 +256,7 @@ <h3 class="s-title">Accordions<a class="anchor" href="#accordions" aria-hidden="
</div>
</div>
<div class="accordion">
<input id="accordion-6" type="checkbox" name="accordion-checkbox" hidden="">
<input class="text-assistive" id="accordion-6" type="checkbox" name="accordion-checkbox">
<label class="accordion-header c-hand" for="accordion-6">Components</label>
<div class="accordion-body">
<ul class="menu menu-nav">
Expand All @@ -269,7 +269,7 @@ <h3 class="s-title">Accordions<a class="anchor" href="#accordions" aria-hidden="
</div>
<pre class="code" data-lang="HTML"><code><span class="hljs-comment">&lt;!-- standard Accordions example --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"accordion"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"checkbox"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"accordion-1"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"accordion-checkbox"</span> <span class="hljs-attr">hidden</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"checkbox"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"accordion-1"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"accordion-checkbox"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text-assistive"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"accordion-header"</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"accordion-1"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">i</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"icon icon-arrow-right mr-1"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">i</span>&gt;</span>
Title
Expand All @@ -281,7 +281,7 @@ <h3 class="s-title">Accordions<a class="anchor" href="#accordions" aria-hidden="

<span class="hljs-comment">&lt;!-- mutually exclusive Accordions example (with same input names) --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"accordion"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"radio"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"accordion-1"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"accordion-radio"</span> <span class="hljs-attr">hidden</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"radio"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"accordion-1"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"accordion-radio"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text-assistive"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"accordion-header"</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"accordion-1"</span>&gt;</span>
Title
<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
Expand Down
4 changes: 4 additions & 0 deletions docs/dist/spectre-rtl.css
Original file line number Diff line number Diff line change
Expand Up @@ -1964,6 +1964,10 @@ video.video-responsive::before {
text-decoration: none;
}

.accordion [type=radio]:focus + label,
.accordion [type=checkbox]:focus + label {
box-shadow: 0 0 0 .1rem rgba(87, 85, 217, .2);
}
.accordion input:checked ~ .accordion-header > .icon:first-child,
.accordion[open] .accordion-header > .icon:first-child {
transform: rotate(90deg);
Expand Down
2 changes: 1 addition & 1 deletion docs/dist/spectre-rtl.min.css

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions docs/dist/spectre.css
Original file line number Diff line number Diff line change
Expand Up @@ -1963,6 +1963,10 @@ video.video-responsive::before {
text-decoration: none;
}

.accordion [type=radio]:focus + label,
.accordion [type=checkbox]:focus + label {
box-shadow: 0 0 0 .1rem rgba(87, 85, 217, .2);
}
.accordion input:checked ~ .accordion-header > .icon:first-child,
.accordion[open] .accordion-header > .icon:first-child {
transform: rotate(90deg);
Expand Down
2 changes: 1 addition & 1 deletion docs/dist/spectre.min.css

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions docs/src/components/accordions.pug
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ block docs-content
.docs-demo.columns
.column.col-6.col-md-12
.accordion
input#accordion-1(type="radio" name="accordion-radio" hidden="" checked="")
input#accordion-1(type="radio" name="accordion-radio" checked="" class="text-assistive")
label.accordion-header.c-hand(for="accordion-1")
i.icon.icon-arrow-right.mr-1
| Elements
Expand All @@ -26,7 +26,7 @@ block docs-content
li.menu-item
a(href="#accordions") Element 2
.accordion
input#accordion-2(type="radio" name="accordion-radio" hidden="")
input#accordion-2(type="radio" name="accordion-radio" class="text-assistive")
label.accordion-header.c-hand(for="accordion-2")
i.icon.icon-arrow-right.mr-1
| Layout
Expand All @@ -37,7 +37,7 @@ block docs-content
li.menu-item
a(href="#accordions") Layout 2
.accordion
input#accordion-3(type="radio" name="accordion-radio" hidden="")
input#accordion-3(type="radio" name="accordion-radio" class="text-assistive")
label.accordion-header.c-hand(for="accordion-3")
i.icon.icon-arrow-right.mr-1
| Components
Expand All @@ -49,7 +49,7 @@ block docs-content
a(href="#accordions") Component 2
.column.col-6.col-md-12
.accordion
input#accordion-4(type="checkbox" name="accordion-checkbox" hidden="" checked="")
input#accordion-4(type="checkbox" name="accordion-checkbox" checked="" class="text-assistive")
label.accordion-header.c-hand(for="accordion-4")
| Elements
.accordion-body
Expand All @@ -59,7 +59,7 @@ block docs-content
li.menu-item
a(href="#accordions") Element 2
.accordion
input#accordion-5(type="checkbox" name="accordion-checkbox" hidden="")
input#accordion-5(type="checkbox" name="accordion-checkbox" class="text-assistive")
label.accordion-header.c-hand(for="accordion-5")
| Layout
.accordion-body
Expand All @@ -69,7 +69,7 @@ block docs-content
li.menu-item
a(href="#accordions") Layout 2
.accordion
input#accordion-6(type="checkbox" name="accordion-checkbox" hidden="")
input#accordion-6(type="checkbox" name="accordion-checkbox" class="text-assistive")
label.accordion-header.c-hand(for="accordion-6")
| Components
.accordion-body
Expand All @@ -84,7 +84,7 @@ block docs-content
:highlight(lang="html")
<!-- standard Accordions example -->
<div class="accordion">
<input type="checkbox" id="accordion-1" name="accordion-checkbox" hidden>
<input type="checkbox" id="accordion-1" name="accordion-checkbox" class="text-assistive">
<label class="accordion-header" for="accordion-1">
<i class="icon icon-arrow-right mr-1"></i>
Title
Expand All @@ -96,7 +96,7 @@ block docs-content

<!-- mutually exclusive Accordions example (with same input names) -->
<div class="accordion">
<input type="radio" id="accordion-1" name="accordion-radio" hidden>
<input type="radio" id="accordion-1" name="accordion-radio" class="text-assistive">
<label class="accordion-header" for="accordion-1">
Title
</label>
Expand Down
14 changes: 12 additions & 2 deletions src/_accordions.scss
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
@use "variables";
@use "mixins/shadow";

// Accordions
.accordion {
[type="radio"],
[type="checkbox"] {
&:focus {
+ label {
@include shadow.control-shadow();
}
}
}

input:checked ~,
&[open] {
& .accordion-header > {
.accordion-header > {
.icon:first-child {
transform: rotate(90deg);
}
}

& .accordion-body {
.accordion-body {
max-height: 50rem;
}
}
Expand Down
Binary file modified tests/snapshots/__base_images__/Accordions_1600x900.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.