2018-10-09 11:35:22 +02:00
|
|
|
import { delegate } from '@utils';
|
2018-09-11 17:51:44 +02:00
|
|
|
|
2020-04-30 15:42:29 +02:00
|
|
|
delegate('click', 'body', (event) => {
|
2021-04-23 13:45:04 +02:00
|
|
|
if (!event.target.closest('.dropdown, [data-reach-combobox-popover]')) {
|
2020-09-08 18:32:06 +02:00
|
|
|
[...document.querySelectorAll('.dropdown')].forEach((element) => {
|
|
|
|
const button = element.querySelector('.dropdown-button');
|
|
|
|
button.setAttribute('aria-expanded', false);
|
|
|
|
element.classList.remove('open', 'fade-in-down');
|
|
|
|
});
|
2018-09-11 17:51:44 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-04-30 15:42:29 +02:00
|
|
|
delegate('click', '.dropdown-button', (event) => {
|
2018-09-11 17:51:44 +02:00
|
|
|
event.stopPropagation();
|
2020-09-08 18:32:06 +02:00
|
|
|
const button = event.target.closest('.dropdown-button');
|
|
|
|
const parent = button.parentElement;
|
2018-09-11 17:51:44 +02:00
|
|
|
if (parent.classList.contains('dropdown')) {
|
|
|
|
parent.classList.toggle('open');
|
2020-09-08 18:32:06 +02:00
|
|
|
var buttonExpanded = button.getAttribute('aria-expanded') === 'true';
|
|
|
|
button.setAttribute('aria-expanded', !buttonExpanded);
|
2018-09-11 17:51:44 +02:00
|
|
|
}
|
|
|
|
});
|