From 8eeb709675859012e5c11b9ce844bdffbacdcf48 Mon Sep 17 00:00:00 2001 From: June Hansen <44864244+Kahera@users.noreply.github.com> Date: Sun, 14 Jan 2024 19:49:23 +0100 Subject: [PATCH] Ensuring language selector component is created anew when screen size change, to avoid css being wrong if language has been changed between changing screen sizes --- src/components/NavbarComponent.vue | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/components/NavbarComponent.vue b/src/components/NavbarComponent.vue index aa9d554..61f1643 100644 --- a/src/components/NavbarComponent.vue +++ b/src/components/NavbarComponent.vue @@ -8,10 +8,18 @@ import { useDarkModeStore } from '@/stores/darkMode'; import Dropdown from '@/components/DropdownComponent.vue'; import Button from '@/components/ButtonComponent.vue'; import LanguageSelector from './LanguageSelector.vue'; +import { onUnmounted, ref } from 'vue'; // Variables const darkModeStore = useDarkModeStore(); +// Screen size variable +const isSmallScreen = ref(false); +checkWindowSize(); +function checkWindowSize() { + isSmallScreen.value = window.matchMedia('(max-width: 768px)').matches; +} +window.addEventListener('resize', () => checkWindowSize()); function getNavIcon(name: string | undefined) { switch (name) { @@ -26,6 +34,8 @@ function getNavIcon(name: string | undefined) { } } +// Destroy event listener on unmount +onUnmounted(() => window.removeEventListener('resize', () => checkWindowSize()));