Skip to content

Commit

Permalink
accessibility-enhancement/beforematch/hidden=until-found (#421)
Browse files Browse the repository at this point in the history
* Added event listener for 'beforematch' to expand accordion and updated hidden from true to 'until-found' making collapsed content accessible

* Update _accordion.scss
  • Loading branch information
laurenhitchon authored Jun 12, 2024
1 parent d399d3d commit ff00147
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/components/accordion/_accordion.scss
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@
}
}

&__content[hidden='until-found'] {
padding: 0;
}

&__content {
padding: rem(16px);
}
Expand Down
10 changes: 6 additions & 4 deletions src/components/accordion/accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
Expand All @@ -95,25 +96,26 @@ 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')
}

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')
}
}
}
Expand Down

0 comments on commit ff00147

Please sign in to comment.