Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(accordion): Removing outdated code in the js - FRONT-4465 #3438

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 3 additions & 26 deletions src/implementations/vanilla/components/accordion/accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export class Accordion {
this.target = null;

// Bind `this` for use in callbacks
this.handleClickOutside = this.handleClickOutside.bind(this);
this.handleClickOnToggle = this.handleClickOnToggle.bind(this);
}

Expand All @@ -75,15 +74,13 @@ export class Accordion {
}
ECL.components = ECL.components || new Map();

document.addEventListener('click', this.handleClickOutside);

this.toggles = queryAll(this.toggleSelector, this.element);

// Bind click event on toggles
if (this.attachClickListener && this.toggles) {
this.toggles.forEach((toggle) => {
toggle.addEventListener('click', (event) =>
this.handleClickOnToggle(event, toggle),
toggle.addEventListener('click', () =>
this.handleClickOnToggle(toggle),
);
});
}
Expand Down Expand Up @@ -128,7 +125,6 @@ export class Accordion {
* Destroy component.
*/
destroy() {
document.removeEventListener('click', this.handleClickOutside);
if (this.attachClickListener && this.toggles) {
this.toggles.forEach((toggle) => {
toggle.replaceWith(toggle.cloneNode(true));
Expand All @@ -140,23 +136,12 @@ export class Accordion {
}
}

/**
* @param {e} Event
*/
handleClickOutside(e) {
if (e.target && this.toggles && !this.element.contains(e.target)) {
this.toggles.forEach((item) =>
item.classList.remove('ecl-accordion__toggle--active'),
);
}
}

/**
* @param {HTMLElement} toggle Target element to toggle.
*
* @fires Accordion#onToggle
*/
handleClickOnToggle(event, toggle) {
handleClickOnToggle(toggle) {
let isOpening = false;
// Get target element
const target = queryOne(
Expand Down Expand Up @@ -204,14 +189,6 @@ export class Accordion {
useNode.setAttribute('xlink:href', newXlinkHref);
}
}

this.toggles.forEach((item) =>
item.classList.remove('ecl-accordion__toggle--active'),
);
// This is the way we distinguish the click from a press on Enter
if (event.detail > 0) {
toggle.classList.add('ecl-accordion__toggle--active');
}
}
}

Expand Down
Loading