Added bindMenu to remove menu on external click.
This commit is contained in:
parent
96c2634fdc
commit
f4e92c65bf
1 changed files with 11 additions and 2 deletions
|
|
@ -1,9 +1,9 @@
|
||||||
export const bindEvents = () => {
|
export const bindConfig = () => {
|
||||||
document.querySelectorAll('a[data-click]').forEach((e) => {
|
document.querySelectorAll('a[data-click]').forEach((e) => {
|
||||||
e.addEventListener('click', (evt) => {
|
e.addEventListener('click', (evt) => {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
const dialog = document.querySelector('dialog.'+e.getAttribute('data-click'));
|
const dialog = document.querySelector('dialog.'+e.getAttribute('data-click'));
|
||||||
document.querySelector('#menu-toggle').checked = false;
|
document.getElementById('menu-toggle').checked = false;
|
||||||
dialog?.classList.remove('hidden');
|
dialog?.classList.remove('hidden');
|
||||||
dialog?.showModal();
|
dialog?.showModal();
|
||||||
dialog?.addEventListener('click', (evt) => {
|
dialog?.addEventListener('click', (evt) => {
|
||||||
|
|
@ -15,3 +15,12 @@ export const bindEvents = () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const bindMenu = () => {
|
||||||
|
const menu = document.getElementById('nav-menu');
|
||||||
|
window.addEventListener('click', (evt) => {
|
||||||
|
if (!evt.composedPath().includes(menu)) {
|
||||||
|
document.getElementById('menu-toggle').checked = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
Loading…
Reference in a new issue