Skip to content

Commit

Permalink
fix: expand sidebar items with links
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Aug 14, 2024
1 parent 71f0ab3 commit d29b41e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/cyan-toes-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vocs": patch
---

Expand collapsed sidebar items when they have a link and are pressed.
30 changes: 13 additions & 17 deletions src/app/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,23 +136,16 @@ function SidebarItem(props: {
if (hasActiveChildItem) return false
return Boolean(item.collapsed)
})

const isCollapsable = item.collapsed !== undefined && item.items !== undefined
const onCollapseInteraction = useCallback(
(event: KeyboardEvent | MouseEvent) => {
if ('key' in event && event.key !== 'Enter') return
if (item.link) return
setCollapsed((x) => !x)
},
[item.link],
)
const onCollapseTriggerInteraction = useCallback(
(event: KeyboardEvent | MouseEvent) => {
if ('key' in event && event.key !== 'Enter') return
if (!item.link) return
setCollapsed((x) => !x)
},
[item.link],
)
const onCollapseInteraction = useCallback((event: KeyboardEvent | MouseEvent) => {
if ('key' in event && event.key !== 'Enter') return
setCollapsed((x) => !x)
}, [])
const onCollapseTriggerInteraction = useCallback((event: KeyboardEvent | MouseEvent) => {
if ('key' in event && event.key !== 'Enter') return
setCollapsed((x) => !x)
}, [])

const active = useRef(true)
useEffect(() => {
Expand Down Expand Up @@ -196,7 +189,10 @@ function SidebarItem(props: {
(item.link ? (
<RouterLink
data-active={Boolean(match)}
onClick={onClick}
onClick={(e) => {
onClick?.(e)
onCollapseInteraction(e)
}}
className={clsx(
depth === 0 ? [styles.sectionTitle, styles.sectionTitleLink] : styles.item,
hasActiveChildItem && styles.sectionHeaderActive,
Expand Down

0 comments on commit d29b41e

Please sign in to comment.