Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix collapsible nav titles now redirect to their first sub-nav option and highlight when selected #178

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/fuzzy-tomatoes-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vocs": patch
---

Fixed collapsible nav titles now redirect to their first sub-nav option and highlight when selected.
11 changes: 11 additions & 0 deletions src/app/components/Sidebar.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,17 @@ export const sectionTitle = style(
'sectionTitle',
)

export const sectionTitleActive = style(
{
color: primitiveColorVars.textAccent,
fontSize: fontSizeVars['14'],
fontWeight: fontWeightVars.semibold,
letterSpacing: '0.25px',
width: '100%',
},
'sectionTitleActive',
)

export const sectionTitleLink = style(
{
selectors: {
Expand Down
31 changes: 29 additions & 2 deletions src/app/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ import { RouterLink } from './RouterLink.js'
import * as styles from './Sidebar.css.js'
import { ChevronRight } from './icons/ChevronRight.js'

function checkSectionTitleActive(items: any[], pathname: string) {
const result = Boolean(
items.find((item) => {
if (item.link) {
return item.link === pathname
}
return false
}),
)

return !!result
}

export function Sidebar(props: {
className?: string
onClickItem?: MouseEventHandler<HTMLAnchorElement>
Expand Down Expand Up @@ -206,8 +219,22 @@ function SidebarItem(props: {
{item.text}
</RouterLink>
) : (
<div className={clsx(depth === 0 ? styles.sectionTitle : styles.item)}>
{item.text}
<div
className={clsx(
depth === 0
? item.items && checkSectionTitleActive(item.items, pathname)
? styles.sectionTitleActive
: styles.sectionTitle
: styles.item,
)}
>
{item.items && !checkSectionTitleActive(item.items, pathname) && collapsed ? (
<RouterLink data-active={false} onClick={onClick} to={item.items[0].link!}>
{item.text}
</RouterLink>
) : (
item.text
)}
</div>
))}

Expand Down