Skip to content

Commit 9bb89b7

Browse files
authored
feat(ui): close the nav when the user navigates away on small screens (#10932)
1 parent d4d2bf4 commit 9bb89b7

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

packages/ui/src/elements/Nav/context.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use client'
22
import { useWindowInfo } from '@faceless-ui/window-info'
3+
import { usePathname } from 'next/navigation.js'
34
import React, { useEffect, useRef } from 'react'
45

56
import { usePreferences } from '../../providers/Preferences/index.js'
@@ -40,6 +41,8 @@ export const NavProvider: React.FC<{
4041
breakpoints: { l: largeBreak, m: midBreak, s: smallBreak },
4142
} = useWindowInfo()
4243

44+
const pathname = usePathname()
45+
4346
const { getPreference } = usePreferences()
4447
const navRef = useRef(null)
4548

@@ -64,8 +67,13 @@ export const NavProvider: React.FC<{
6467
}
6568
}, [largeBreak, getPreference, setNavOpen])
6669

67-
// TODO: on smaller screens where the nav is a modal
70+
// on smaller screens where the nav is a modal
6871
// close the nav when the user navigates away
72+
useEffect(() => {
73+
if (smallBreak === true) {
74+
setNavOpen(false)
75+
}
76+
}, [pathname])
6977

7078
// on open and close, lock the body scroll
7179
// do not do this on desktop, the sidebar is not a modal

0 commit comments

Comments
 (0)