Skip to content

Commit

Permalink
feat(accordion): ajoute un attribut group pour dissocier le disclose-…
Browse files Browse the repository at this point in the history
…group
  • Loading branch information
zellerbaptiste committed Jan 30, 2024
1 parent b92cf6e commit 9a6ab02
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/component/accordion/example/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -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); %>
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand Down
6 changes: 2 additions & 4 deletions src/component/accordion/template/ejs/accordions-group.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
<%
let accordionsGroup = locals.accordionsGroup || {accordions: []}
let classes = accordionsGroup.classes || [];
classes.push(prefix + '-accordions-group');
if (accordionsGroup.dissociate) classes.push(prefix + '-accordions-group--dissociate');
let attributes = accordionsGroup.attributes || {};
%>
<div <%- includeClasses(classes); %>>
<div <%- includeAttrs(attributes); %> class="<%= prefix %>-accordions-group">
<%
for (let i = 0; i < accordionsGroup.accordions.length; i++) {
%>
Expand Down
17 changes: 16 additions & 1 deletion src/core/script/disclosure/disclosures-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class DisclosuresGroup extends Instance {
}

update () {
this._isGrouped = this.isGrouped;
this.getMembers();
if (this._hasRetrieved) this.getIndex();
}
Expand Down Expand Up @@ -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();
Expand All @@ -155,13 +156,27 @@ class DisclosuresGroup extends Instance {
return false;
}

get isGrouped () {
return this.getAttribute('group');
}

set isGrouped (value) {
this._isGrouped = value;
}

apply () {}

dispose () {
super.dispose();
this.descend(DisclosureEmission.UNGROUP);
this._members = null;
}

mutate (attributesNames) {
if (attributesNames.includes('group')) {
this.update();
}
}
}

export { DisclosuresGroup };

0 comments on commit 9a6ab02

Please sign in to comment.