demarches-normaliennes/app/javascript/new_design/dropdown.js
2020-05-12 18:18:37 +02:00

17 lines
502 B
JavaScript

import { delegate } from '@utils';
delegate('click', 'body', (event) => {
if (!event.target.closest('.dropdown')) {
[...document.querySelectorAll('.dropdown')].forEach((element) =>
element.classList.remove('open', 'fade-in-down')
);
}
});
delegate('click', '.dropdown-button', (event) => {
event.stopPropagation();
const parent = event.target.closest('.dropdown-button').parentElement;
if (parent.classList.contains('dropdown')) {
parent.classList.toggle('open');
}
});