diff --git a/src/js/lazily-loaded/Collapsible.js b/src/js/lazily-loaded/Collapsible.js index 588f222..0612695 100644 --- a/src/js/lazily-loaded/Collapsible.js +++ b/src/js/lazily-loaded/Collapsible.js @@ -224,12 +224,12 @@ class Collapsible { if (event.target.playbackRate * (reverse ? 1 : -1) > 0) { this.node.classList.remove(this.constructor.classes.active) - this.node.setAttribute('aria-expanded', false) + this.trigger.setAttribute('aria-expanded', false) this.setStartState() return } this.node.classList.add(this.constructor.classes.active) - this.node.setAttribute('aria-expanded', true) + this.trigger.setAttribute('aria-expanded', true) this.setEndState() } @@ -260,9 +260,11 @@ class Collapsible { if (this.initiallyOpen) { this.node.classList.add(this.constructor.classes.active) - this.node.setAttribute('aria-expanded', true) + this.trigger.setAttribute('aria-expanded', true) this.setEndState() return + } else { + this.trigger.setAttribute('aria-expanded', false) } this.setStartState() } diff --git a/src/js/lazily-loaded/Tabs.js b/src/js/lazily-loaded/Tabs.js index 304733c..6226960 100644 --- a/src/js/lazily-loaded/Tabs.js +++ b/src/js/lazily-loaded/Tabs.js @@ -10,6 +10,11 @@ class Tabs { removeAllActiveTabs(activeTabs) { for (let i = 0; i < activeTabs.length; i++) { const prevActiveTab = activeTabs[i] + if (prevActiveTab.classList.contains('tab-anchor')) { + prevActiveTab.setAttribute('aria-selected', 'false') + } else { + prevActiveTab.setAttribute('aria-hidden', 'true') + } prevActiveTab.classList.remove('activeTab') } } @@ -23,11 +28,14 @@ class Tabs { this.removeAllActiveTabs(activeTabs) anchor.classList.add('activeTab') + anchor.setAttribute('aria-selected', 'true') + const panelID = anchor.dataset.href const panel = parent.querySelector( `:scope > .tabs__content > [data-id="${panelID}"]` ) panel.classList.add('activeTab') + panel.setAttribute('aria-hidden', 'false') } init() { diff --git a/views/parts/_accordion.latte b/views/parts/_accordion.latte index b0451bd..b77e301 100644 --- a/views/parts/_accordion.latte +++ b/views/parts/_accordion.latte @@ -6,6 +6,16 @@ {varType bool $collapse_siblings} {* Whether or not opening one accordion items should close siblings. Default is falses *} {varType int $initially_open_item} {* By default all accordion items are closed. This can be used, and index passed to make one open by default *} + + +{* panels ids - required for a11y purposes *} +{var $panels_ids = []} +{var $random_string = uniqid()} +{foreach $items as $acc_index => $tab_content} + {var $index = $acc_index + 1} + {var $panels_ids[] = "{$random_string}_{$index}"} +{/foreach} +