@@ -19,6 +19,7 @@ import {
1919} from '@tanstack/react-router' ;
2020import { Link } from '@tanstack/react-router' ;
2121import { defineQuery } from 'groq' ;
22+ import { useEffect , useState } from 'react' ;
2223
2324const COMPONENTS_NAVIGATION_QUERY = defineQuery (
2425 // make sure the slug is always a string so we don't have add fallback value in code just to make TypeScript happy
@@ -42,6 +43,18 @@ export const Route = createFileRoute('/_docs')({
4243function RootLayout ( ) {
4344 const router = useRouter ( ) ;
4445
46+ const [ isMobileNavExpanded , setIsMobileNavExpanded ] = useState ( false ) ;
47+
48+ useEffect ( ( ) => {
49+ const unsubscribe = router . history . subscribe ( ( ) => {
50+ setIsMobileNavExpanded ( false ) ;
51+ } ) ;
52+
53+ return ( ) => {
54+ unsubscribe ( ) ;
55+ } ;
56+ } , [ router ] ) ;
57+
4558 return (
4659 < >
4760 < GrunnmurenProvider
@@ -52,32 +65,31 @@ function RootLayout() {
5265 navigate = { ( to , options ) => router . navigate ( { to, ...options } ) }
5366 useHref = { ( to ) => router . buildLocation ( { to } ) . href }
5467 >
55- < Disclosure >
56- { ( { isExpanded } ) => (
57- < >
58- < header className = "relative z-[3] flex items-center justify-between bg-blue-dark px-8 py-2 text-white" >
59- < Link to = "/" aria-label = "Gå til forsiden" className = "py-2.5" >
60- < img src = { logoUrl } alt = "" className = "h-6" />
61- </ Link >
62- < DisclosureButton className = "lg:hidden" aria-label = "Meny" >
63- { isExpanded ? (
64- < Close className = "h-6 w-6" />
65- ) : (
66- < Menu className = "h-6 w-6" />
67- ) }
68- </ DisclosureButton >
69- </ header >
70- < div className = "relative lg:hidden" >
71- < div className = "absolute top-0 left-0 z-[3] w-full" >
72- < DisclosurePanel >
73- < MainNav className = "min-h-svh" />
74- </ DisclosurePanel >
75- </ div >
76- </ div >
77- { isExpanded && (
78- < div className = "absolute inset-0 z-[2] bg-black opacity-70" />
68+ < Disclosure
69+ isExpanded = { isMobileNavExpanded }
70+ onExpandedChange = { setIsMobileNavExpanded }
71+ >
72+ < header className = "relative z-[3] flex items-center justify-between bg-blue-dark px-8 py-2 text-white" >
73+ < Link to = "/" aria-label = "Gå til forsiden" className = "py-2.5" >
74+ < img src = { logoUrl } alt = "" className = "h-6" />
75+ </ Link >
76+ < DisclosureButton className = "lg:hidden" aria-label = "Meny" >
77+ { isMobileNavExpanded ? (
78+ < Close className = "h-6 w-6" />
79+ ) : (
80+ < Menu className = "h-6 w-6" />
7981 ) }
80- </ >
82+ </ DisclosureButton >
83+ </ header >
84+ < div className = "relative lg:hidden" >
85+ < div className = "absolute top-0 left-0 z-[3] w-full" >
86+ < DisclosurePanel >
87+ < MainNav className = "min-h-svh" />
88+ </ DisclosurePanel >
89+ </ div >
90+ </ div >
91+ { isMobileNavExpanded && (
92+ < div className = "absolute inset-0 z-[2] bg-black opacity-70 lg:hidden" />
8193 ) }
8294 </ Disclosure >
8395
0 commit comments