Skip to content

Commit 954c487

Browse files
author
Eric Olkowski
committed
fix(PageToggle): resolved sidebar not collapsing correctly
1 parent 48449a1 commit 954c487

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

src/components/PageToggle.tsx

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type React from 'react'
22
import { PageToggleButton } from '@patternfly/react-core'
3+
import styles from '@patternfly/react-styles/css/components/Page/page'
34
import BarsIcon from '@patternfly/react-icons/dist/esm/icons/bars-icon'
45
import { useStore } from '@nanostores/react'
56
import { isNavOpen } from '../stores/navStore'
@@ -8,38 +9,26 @@ import { useEffect } from 'react'
89
export const PageToggle: React.FunctionComponent = () => {
910
const $isNavOpen = useStore(isNavOpen)
1011

11-
/** Applies sidebar styles to the island element astro creates as a wrapper for the sidebar.
12-
* Without it the page content will not expand to fill the space left by the sidebar when it is collapsed.
13-
*/
14-
function applySidebarStylesToIsland() {
15-
const isClientSide = typeof window !== 'undefined'
16-
const sideBarIsland = document.getElementById('page-sidebar')?.parentElement
17-
18-
if (!isClientSide || !sideBarIsland) {
19-
return
20-
}
21-
22-
if (!sideBarIsland.classList.contains('pf-v6-c-page__sidebar')) {
23-
sideBarIsland.classList.add('pf-v6-c-page__sidebar', 'pf-m-expanded')
24-
} else {
25-
sideBarIsland.classList.toggle('pf-m-expanded')
26-
sideBarIsland.classList.toggle('pf-m-collapsed')
27-
}
28-
}
29-
3012
function onToggle() {
3113
isNavOpen.set(!$isNavOpen)
3214
}
3315

3416
useEffect(() => {
35-
applySidebarStylesToIsland()
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+
}
3625
}, [$isNavOpen])
3726

3827
return (
3928
<PageToggleButton
40-
variant="plain"
4129
aria-label="Global navigation"
4230
onSidebarToggle={onToggle}
31+
isSidebarOpen={$isNavOpen}
4332
>
4433
<BarsIcon />
4534
</PageToggleButton>

0 commit comments

Comments
 (0)