diff --git a/src/components/Navigations/SideMenuButton.vue b/src/components/Navigations/SideMenuButton.vue
index cfca928..08e5164 100644
--- a/src/components/Navigations/SideMenuButton.vue
+++ b/src/components/Navigations/SideMenuButton.vue
@@ -11,7 +11,7 @@ function onClick() {
diff --git a/src/components/Navigations/TopNavbar.vue b/src/components/Navigations/TopNavbar.vue
index c20d847..4644930 100644
--- a/src/components/Navigations/TopNavbar.vue
+++ b/src/components/Navigations/TopNavbar.vue
@@ -11,31 +11,19 @@ defineProps({
const isMenuOpen = ref(false)
-const handler = (e: MouseEvent) => {
- if (e.target instanceof HTMLElement) {
- if (e.target.closest('#top-navbar-menu')) {
- return
- }
- closeMenu()
- }
+const modalHandler = (e: MouseEvent) => {
+ if (!(e.target instanceof HTMLElement) || e.target.closest('#top-navbar-menu')) return
+ setMenuState(false)
}
const toggleMenu = () => {
- if (isMenuOpen.value) {
- closeMenu()
- } else {
- openMenu()
- }
+ setMenuState(!(isMenuOpen.value as boolean))
}
-const openMenu = () => {
- isMenuOpen.value = true
- document.addEventListener('mousedown', handler)
-}
-
-const closeMenu = () => {
- isMenuOpen.value = false
- document.removeEventListener('mousedown', handler)
+const setMenuState = (state: boolean) => {
+ isMenuOpen.value = state
+ if(state) document.addEventListener('mousedown', modalHandler)
+ else document.removeEventListener('mousedown', modalHandler)
}
@@ -66,17 +54,21 @@ const closeMenu = () => {
}
"
/>
-
+