Skip to content

fix: open the sidebar group by default if active #382

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

Merged
merged 1 commit into from
Apr 6, 2025
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
10 changes: 8 additions & 2 deletions app/components/DocsLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
GadLeftRailSquare,
GadRightRailSquare,
} from './GoogleScripts'
import { DocContainer } from './DocContainer'

Check warning on line 38 in app/components/DocsLayout.tsx

View workflow job for this annotation

GitHub Actions / PR

'DocContainer' is defined but never used

// Let's use zustand to wrap the local storage logic. This way
// we'll get subscriptions for free and we can use it in other
Expand Down Expand Up @@ -324,6 +324,7 @@
const { libraryId } = useParams({
from: '/$libraryId/$version/docs',
})
const { _splat } = useParams({ strict: false })
const frameworkConfig = useFrameworkConfig({ frameworks })
const versionConfig = useVersionConfig({ versions })
const menuConfig = useMenuConfig({ config, frameworks, repo })
Expand Down Expand Up @@ -367,9 +368,14 @@
const WrapperComp = group.collapsible ? 'details' : 'div'
const LabelComp = group.collapsible ? 'summary' : 'div'

const isCollapsed = group.defaultCollapsed ?? false
const isChildActive = group.children.some((d) => d.to === _splat)
const configGroupOpenState =
typeof group.defaultCollapsed !== 'undefined'
? !group.defaultCollapsed // defaultCollapsed is true means the group is closed
: undefined
const isOpen = isChildActive ? true : configGroupOpenState ?? false

const detailsProps = group.collapsible ? { open: !isCollapsed } : {}
const detailsProps = group.collapsible ? { open: isOpen } : {}

return (
<WrapperComp
Expand Down
Loading