better accessibility for details component

This commit is contained in:
madrilene 2024-02-09 09:53:50 +01:00
parent 4a85ae5fd4
commit 010051f823
3 changed files with 22 additions and 6 deletions

View file

@ -40,7 +40,9 @@ module.exports = {
paginationNext: 'Next' paginationNext: 'Next'
}, },
details: { details: {
toggle: 'Toggle all' aria: 'section controls',
expand: 'expand all',
collapse: 'collapse all'
}, },
navigation: { navigation: {
ariaTop: 'Main', ariaTop: 'Main',

View file

@ -1,4 +1,7 @@
<button id="toggleAll" class="button">{{ meta.details.toggle }}</button> <ul class="control | cluster" aria-label="{{ meta.details.aria }}">
<button id="expandAll" class="button post-tag">{{ meta.details.expand }}</button>
<button id="collapseAll" class="button post-tag">{{ meta.details.collapse }}</button>
</ul>
{% for item in itemList %} {% for item in itemList %}
<details id="{{ item.data.title | slugify }}"> <details id="{{ item.data.title | slugify }}">
@ -8,12 +11,16 @@
{% endfor %} {% endfor %}
<script> <script>
const toggleAll = document.querySelector('#toggleAll'); const expandAllButton = document.querySelector('#expandAll');
const collapseAllButton = document.querySelector('#collapseAll');
const details = document.querySelectorAll('details'); const details = document.querySelectorAll('details');
toggleAll.addEventListener('click', () => { expandAllButton.addEventListener('click', () => {
const allOpen = [...details].every(detail => detail.open); details.forEach(detail => (detail.open = true));
details.forEach(detail => (detail.open = !allOpen)); });
collapseAllButton.addEventListener('click', () => {
details.forEach(detail => (detail.open = false));
}); });
details.forEach(detail => { details.forEach(detail => {

View file

@ -1,3 +1,10 @@
.control {
--gutter: var(--space-xs-s);
--cluster-horizontal-alignment: flex-end;
border-block-start: 1px solid var(--color-bg-accent);
padding-block-start: var(--space-xs);
}
details > * + * { details > * + * {
margin-block-start: var(--flow-space, 1em); margin-block-start: var(--flow-space, 1em);
} }