@@ -9,19 +9,37 @@ import { useEffect } from 'react'
99export 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