diff --git a/packages/vanilla/src/components/accordion/accordion.js b/packages/vanilla/src/components/accordion/accordion.js
index a0270b72..12420be4 100644
--- a/packages/vanilla/src/components/accordion/accordion.js
+++ b/packages/vanilla/src/components/accordion/accordion.js
@@ -1,13 +1,25 @@
class Accordion {
- constructor(domNode) {
- this.accordionNode = domNode;
+ constructor(accordion) {
+ this.accordionNode = accordion;
+ this.accordionControl = this.accordionNode.querySelector('.cbp-accordion__control');
+ this.accordionContent = this.accordionNode.querySelector('.cbp-accordion__content');
- this.accordionNode.addEventListener('click', this.toggle);
+ this.accordionControl.setAttribute('aria-expanded', false)
+
+ this.accordionNode.addEventListener('click', () => {
+ this.toggle()
+ });
}
- toggle(event) {
- const wrapper = event.target.closest('.cbp-accordion__item');
- wrapper.classList.toggle('active');
+ toggle() {
+ const previousState =
+ this.accordionControl.hasAttribute('aria-expanded') &&
+ this.accordionControl.getAttribute('aria-expanded') === 'true'
+ ? true
+ : false;
+
+ this.accordionControl.setAttribute('aria-expanded', !previousState);
+ this.accordionContent.toggleAttribute('hidden');
}
}
diff --git a/packages/vanilla/src/components/accordion/accordion.stories.js b/packages/vanilla/src/components/accordion/accordion.stories.js
index 151a7306..cc01b335 100644
--- a/packages/vanilla/src/components/accordion/accordion.stories.js
+++ b/packages/vanilla/src/components/accordion/accordion.stories.js
@@ -1,52 +1,59 @@
export default {
title: 'Patterns/Accordion',
argTypes: {
- label: { control: 'text' },
- onClick: { action: 'onClick' },
- },
+ defaultAccordion: {
+ name: 'Accordion (Default)',
+ },
+ badgeAccordion: {
+ name: 'Accordion w/ Badge',
+ },
+ iconAccordion: {
+ name: 'Accordion w/ Icon',
+ }
+ }
};
-
-
-const Template = ({ label, ...args }) => {
+const Template = ({ defaultAccordion, badgeAccordion, iconAccordion }) => {
return `
-
-