Skip to content

Commit

Permalink
fix(UsaNav): support ssr by adding mounted check to media query evalu…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
patrickcate committed Feb 19, 2024
1 parent 399093c commit aefd68f
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/components/UsaNav/UsaNav.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<script setup>
import { computed, ref, watch, onBeforeUnmount, nextTick, inject, h } from 'vue'
import {
computed,
ref,
watch,
onMounted,
onBeforeUnmount,
nextTick,
inject,
h,
} from 'vue'
import { IMAGE_PATH, MOBILE_MENU_BREAKPOINT } from '@/utils/constants.js'
import { onKeyStroke, onClickOutside, useMediaQuery } from '@vueuse/core'
import { useFocusTrap } from '@vueuse/integrations/useFocusTrap'
Expand Down Expand Up @@ -38,7 +47,13 @@ const props = defineProps({
const nav = ref(null)
const { activate, deactivate } = useFocusTrap(nav)
const largeScreen = useMediaQuery(`(min-width: ${mobileMenuBreakpoint})`)
const isMounted = ref(false)
const largeScreenMediaQuery = useMediaQuery(
`(min-width: ${mobileMenuBreakpoint})`
)
const largeScreen = computed(() =>
isMounted.value ? largeScreenMediaQuery.value : true
)
watch(isMobileMenuOpen, async isMenuOpen => {
if (isMenuOpen) {
Expand All @@ -56,6 +71,10 @@ watch(largeScreen, isLargeScreen => {
}
})
onMounted(() => {
isMounted.value = true
})
onBeforeUnmount(() => {
if (isMobileMenuOpen.value) {
closeMobileMenu()
Expand Down

0 comments on commit aefd68f

Please sign in to comment.