From 5dcfe825bfa53503f6dd423c8c87a1971531e358 Mon Sep 17 00:00:00 2001 From: zellerbaptiste Date: Tue, 30 Jan 2024 16:24:06 +0100 Subject: [PATCH] feat(accordion): ajoute un attribut group pour dissocier le disclose-group --- src/component/accordion/example/index.ejs | 2 +- .../script/accordion/accordion-selector.js | 2 +- .../accordion/template/ejs/accordions-group.ejs | 4 ++-- src/core/script/disclosure/disclosures-group.js | 17 ++++++++++++++++- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/component/accordion/example/index.ejs b/src/component/accordion/example/index.ejs index d27392d15f..445b930105 100755 --- a/src/component/accordion/example/index.ejs +++ b/src/component/accordion/example/index.ejs @@ -4,4 +4,4 @@ <%- sample('Groupe d‘accordéons', './sample/accordions-group', {}, true); %> -<%- sample('Groupe d‘accordéons dissociés', './sample/accordions-group', {accordionsGroup: {dissociate: true}}, true); %> +<%- sample('Groupe d‘accordéons dissociés', './sample/accordions-group', {accordionsGroup: {attributes: {group: false}}}, true); %> diff --git a/src/component/accordion/script/accordion/accordion-selector.js b/src/component/accordion/script/accordion/accordion-selector.js index 4144c08734..8adffc7ced 100644 --- a/src/component/accordion/script/accordion/accordion-selector.js +++ b/src/component/accordion/script/accordion/accordion-selector.js @@ -4,7 +4,7 @@ const ACCORDION = api.internals.ns.selector('accordion'); const COLLAPSE = api.internals.ns.selector('collapse'); export const AccordionSelector = { - GROUP: `${api.internals.ns.selector('accordions-group')}:not(${api.internals.ns.selector('accordions-group--dissociate')})`, + GROUP: api.internals.ns.selector('accordions-group'), ACCORDION: ACCORDION, COLLAPSE: `${ACCORDION} > ${COLLAPSE}, ${ACCORDION} > *:not(${ACCORDION}):not(${COLLAPSE}) > ${COLLAPSE}, ${ACCORDION} > *:not(${ACCORDION}):not(${COLLAPSE}) > *:not(${ACCORDION}):not(${COLLAPSE}) > ${COLLAPSE}`, COLLAPSE_LEGACY: `${ACCORDION} ${COLLAPSE}`, diff --git a/src/component/accordion/template/ejs/accordions-group.ejs b/src/component/accordion/template/ejs/accordions-group.ejs index 25457351ad..d165d1eea2 100644 --- a/src/component/accordion/template/ejs/accordions-group.ejs +++ b/src/component/accordion/template/ejs/accordions-group.ejs @@ -9,11 +9,11 @@ <% let accordionsGroup = locals.accordionsGroup || {accordions: []} let classes = accordionsGroup.classes || []; +let attributes = accordionsGroup.attributes || {}; classes.push(prefix + '-accordions-group'); -if (accordionsGroup.dissociate) classes.push(prefix + '-accordions-group--dissociate'); %> -
> +
<%- includeClasses(classes); %>> <% for (let i = 0; i < accordionsGroup.accordions.length; i++) { %> diff --git a/src/core/script/disclosure/disclosures-group.js b/src/core/script/disclosure/disclosures-group.js index 8282d532f3..d871ba722c 100644 --- a/src/core/script/disclosure/disclosures-group.js +++ b/src/core/script/disclosure/disclosures-group.js @@ -21,6 +21,7 @@ class DisclosuresGroup extends Instance { this.addAscent(DisclosureEmission.RETRIEVE, this.retrieve.bind(this)); this.addAscent(DisclosureEmission.REMOVED, this.update.bind(this)); this.descend(DisclosureEmission.GROUP); + this._isGrouped = this.isGrouped; this.update(); } @@ -134,7 +135,7 @@ class DisclosuresGroup extends Instance { if (value === i) { if (!member.isDisclosed) member.disclose(true); } else { - if (member.isDisclosed) member.conceal(true); + if (this.isGrouped !== 'false' && member.isDisclosed) member.conceal(true); } } this.apply(); @@ -155,6 +156,14 @@ class DisclosuresGroup extends Instance { return false; } + get isGrouped () { + return this.getAttribute('group'); + } + + set isGrouped (value) { + this._isGrouped = value; + } + apply () {} dispose () { @@ -162,6 +171,12 @@ class DisclosuresGroup extends Instance { this.descend(DisclosureEmission.UNGROUP); this._members = null; } + + mutate (attributesNames) { + if (attributesNames.includes('group')) { + this.update(); + } + } } export { DisclosuresGroup };