Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 62ad561

Browse files
authored
fix: open nav group if pathname has changed (#656)
1 parent 1237444 commit 62ad561

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/components/nav/CollapsibleNavItem.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client'
22

3-
import React, { useId } from 'react'
3+
import React, { useEffect, useId } from 'react'
44
import { Collapsible, CollapsibleTrigger } from '../ui/collapsible'
55
import { ChevronDownIcon } from '@heroicons/react/24/outline'
66
import { cn } from '@/lib/utils'
@@ -36,9 +36,16 @@ const CollapsibleNavItem: React.FC<Props> = ({ group, className }) => {
3636

3737
const { title, items, icon: Icon } = group
3838

39-
const isActive = checkIfActive(items, pathname)
39+
const [isOpen, setIsOpen] = React.useState(checkIfActive(items, pathname))
4040

41-
const [isOpen, setIsOpen] = React.useState(isActive)
41+
useEffect(() => {
42+
const isActive = checkIfActive(items, pathname)
43+
44+
// only open if the group is active
45+
if (isActive) {
46+
setIsOpen(isActive)
47+
}
48+
}, [pathname])
4249

4350
return (
4451
<Collapsible

0 commit comments

Comments
 (0)