From ff00147f820420485e373c755236761d36822b31 Mon Sep 17 00:00:00 2001 From: Lauren Hitchon Date: Wed, 12 Jun 2024 17:46:05 +1000 Subject: [PATCH] accessibility-enhancement/beforematch/hidden=until-found (#421) * Added event listener for 'beforematch' to expand accordion and updated hidden from true to 'until-found' making collapsed content accessible * Update _accordion.scss --- src/components/accordion/_accordion.scss | 4 ++++ src/components/accordion/accordion.js | 10 ++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/components/accordion/_accordion.scss b/src/components/accordion/_accordion.scss index ef6a3df81..1e1728e8e 100644 --- a/src/components/accordion/_accordion.scss +++ b/src/components/accordion/_accordion.scss @@ -118,6 +118,10 @@ } } + &__content[hidden='until-found'] { + padding: 0; + } + &__content { padding: rem(16px); } diff --git a/src/components/accordion/accordion.js b/src/components/accordion/accordion.js index 3410df660..1e80e6e24 100644 --- a/src/components/accordion/accordion.js +++ b/src/components/accordion/accordion.js @@ -55,7 +55,7 @@ class Accordion { if (contentElem) { contentElem.id = buttonElem.getAttribute('aria-controls') - contentElem.hidden = true + contentElem.hidden = 'until-found' this.content.push(contentElem) } @@ -73,6 +73,7 @@ class Accordion { controls() { this.buttons.forEach((element) => { element.addEventListener('click', this.toggleEvent, false) + element.addEventListener('beforematch', this.toggleEvent, false) }) if (this.expandAllBtn && this.collapseAllBtn) { this.expandAllBtn.addEventListener('click', this.expandAllEvent, false) @@ -95,17 +96,18 @@ class Accordion { } else if (state === 'close') { element.classList.remove('active') element.setAttribute('aria-expanded', 'false') - targetContent.hidden = true + targetContent.hidden = 'until-found' } } toggle(event) { const { currentTarget } = event const targetContent = this.getTargetContent(currentTarget) + if (targetContent) { const isHidden = targetContent.hidden - if ((isHidden)) { + if ((isHidden === true) || (isHidden === 'until-found')) { this.setAccordionState(currentTarget, 'open') } else { this.setAccordionState(currentTarget, 'close') @@ -113,7 +115,7 @@ class Accordion { if (this.expandAllBtn && this.collapseAllBtn) { this.expandAllBtn.disabled = this.content.every((item) => item.hidden === false) - this.collapseAllBtn.disabled = this.content.every((item) => item.hidden === true) + this.collapseAllBtn.disabled = this.content.every((item) => item.hidden === 'until-found') } } }