Skip to content

Commit a4e1529

Browse files
author
Eric Olkowski
committed
Updated to alternative approach
1 parent 954c487 commit a4e1529

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

src/components/Navigation.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,11 @@ export const Navigation: React.FunctionComponent<NavigationProps> = ({
4747
})
4848

4949
return (
50-
<PageSidebar isSidebarOpen={$isNavOpen}>
51-
<PageSidebarBody>
52-
<Nav onSelect={onNavSelect}>
53-
<NavList>{navSections}</NavList>
54-
</Nav>
55-
</PageSidebarBody>
56-
</PageSidebar>
50+
// Can possibly add back PageSidebar wrapper when https://github.com/patternfly/patternfly/issues/7377 goes in
51+
<PageSidebarBody id="page-sidebar-body">
52+
<Nav onSelect={onNavSelect}>
53+
<NavList>{navSections}</NavList>
54+
</Nav>
55+
</PageSidebarBody>
5756
)
5857
}

src/components/PageToggle.tsx

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,37 @@ import { useEffect } from 'react'
99
export const PageToggle: React.FunctionComponent = () => {
1010
const $isNavOpen = useStore(isNavOpen)
1111

12+
/** Applies sidebar styles to the island element astro creates as a wrapper for the sidebar.
13+
* Without it the page content will not expand to fill the space left by the sidebar when it is collapsed.
14+
*/
15+
// Possibly can refactor to remove applying classes when https://github.com/patternfly/patternfly/issues/7377 goes in
16+
function applySidebarStylesToIsland() {
17+
const isClientSide = typeof window !== 'undefined'
18+
const sideBarIsland =
19+
document.getElementById('page-sidebar-body')?.parentElement
20+
21+
if (!isClientSide || !sideBarIsland) {
22+
return
23+
}
24+
25+
if (!sideBarIsland.classList.contains('pf-v6-c-page__sidebar')) {
26+
sideBarIsland.classList.add(
27+
'pf-v6-c-page__sidebar',
28+
$isNavOpen ? 'pf-m-expanded' : 'pf-m-collapsed',
29+
)
30+
} else {
31+
sideBarIsland.classList.toggle('pf-m-expanded')
32+
sideBarIsland.classList.toggle('pf-m-collapsed')
33+
}
34+
sideBarIsland.setAttribute('aria-hidden', `${!$isNavOpen}`)
35+
}
36+
1237
function onToggle() {
1338
isNavOpen.set(!$isNavOpen)
1439
}
1540

1641
useEffect(() => {
17-
const pageComp = document.querySelector(`.${styles.page}`);
18-
19-
if (pageComp) {
20-
(pageComp as HTMLElement).style.setProperty(
21-
`--${styles.page}__sidebar--Width`,
22-
$isNavOpen ? '' : '0',
23-
)
24-
}
42+
applySidebarStylesToIsland()
2543
}, [$isNavOpen])
2644

2745
return (

0 commit comments

Comments
 (0)