1
0
mirror of https://github.com/kamranahmedse/developer-roadmap.git synced 2025-08-18 23:21:18 +02:00

Hide account dropdown when user clicks anywhere

This commit is contained in:
Kamran Ahmed
2023-09-22 05:20:28 +01:00
parent 2fa41f583e
commit a58b78bfe9

View File

@@ -19,6 +19,8 @@ function bindEvents() {
...target.closest('button')?.dataset,
};
const accountDropdown = document.querySelector('[data-account-dropdown]');
// If the user clicks on the logout button, remove the token cookie
if (dataset.logoutButton !== undefined) {
e.preventDefault();
@@ -27,6 +29,12 @@ function bindEvents() {
document.querySelector('[data-mobile-nav]')?.classList.remove('hidden');
} else if (dataset.closeMobileNav !== undefined) {
document.querySelector('[data-mobile-nav]')?.classList.add('hidden');
} else if (
accountDropdown &&
!target?.closest('[data-account-dropdown]') &&
!accountDropdown.classList.contains('hidden')
) {
accountDropdown.classList.add('hidden');
}
});