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'
},
details: {
toggle: 'Toggle all'
aria: 'section controls',
expand: 'expand all',
collapse: 'collapse all'
},
navigation: {
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 %}
<details id="{{ item.data.title | slugify }}">
@ -8,12 +11,16 @@
{% endfor %}
<script>
const toggleAll = document.querySelector('#toggleAll');
const expandAllButton = document.querySelector('#expandAll');
const collapseAllButton = document.querySelector('#collapseAll');
const details = document.querySelectorAll('details');
toggleAll.addEventListener('click', () => {
const allOpen = [...details].every(detail => detail.open);
details.forEach(detail => (detail.open = !allOpen));
expandAllButton.addEventListener('click', () => {
details.forEach(detail => (detail.open = true));
});
collapseAllButton.addEventListener('click', () => {
details.forEach(detail => (detail.open = false));
});
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 > * + * {
margin-block-start: var(--flow-space, 1em);
}