Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/components/nav/CollapsibleNavItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,27 @@ import { cn } from '@/lib/utils'
import { NavLink } from './NavLink'
import { usePathname } from 'next/navigation'
import { Button } from '../ui/button'
import { NavGroup } from '@/config/types'
import { NavEntry, NavGroup } from '@/config/types'

interface Props {
group: NavGroup
className?: string
}

const checkIfActive = (items: NavEntry[], pathname: string): boolean => {
return items.some((link) => {
if ('href' in link && link.href === pathname) {
return true
}

if ('items' in link && Array.isArray(link.items)) {
return checkIfActive(link.items, pathname)
}

return false
})
}

const CollapsibleNavItem: React.FC<Props> = ({ group, className }) => {
const pathname = usePathname()

Expand All @@ -22,9 +36,8 @@ const CollapsibleNavItem: React.FC<Props> = ({ group, className }) => {

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

const isActive = items.some(
(link) => 'href' in link && link.href === pathname,
)
const isActive = checkIfActive(items, pathname)

const [isOpen, setIsOpen] = React.useState(isActive)

return (
Expand Down
Loading