Skip to content

Commit ec1b119

Browse files
committed
fix(DrawerPanelContent): collapse space when drawer collapsed
Closes #11938 Have not tested this against OCP but this fixes the core issue where the drawer panel content still takes up width even when closed. After this PR, the panel content is still "display"ed but now takes up width 0. We cannot use `display: none` here as that breaks the drawer opening animation
1 parent 263c485 commit ec1b119

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

packages/react-core/src/components/Drawer/DrawerPanelContent.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export const DrawerPanelContent: React.FunctionComponent<DrawerPanelContentProps
8686
const hidden = isStatic ? false : !isExpanded;
8787
const [isExpandedInternal, setIsExpandedInternal] = useState(!hidden);
8888
const [isFocusTrapActive, setIsFocusTrapActive] = useState(false);
89+
const [shouldCollapseSpace, setShouldCollapseSpace] = useState(hidden);
8990
const previouslyFocusedElement = useRef(null);
9091
let currWidth: number = 0;
9192
let panelRect: DOMRect;
@@ -104,6 +105,7 @@ export const DrawerPanelContent: React.FunctionComponent<DrawerPanelContentProps
104105
useEffect(() => {
105106
if (!isStatic && isExpanded) {
106107
setIsExpandedInternal(isExpanded);
108+
setShouldCollapseSpace(false);
107109
}
108110
}, [isStatic, isExpanded]);
109111

@@ -375,14 +377,21 @@ export const DrawerPanelContent: React.FunctionComponent<DrawerPanelContentProps
375377
onExpand(ev);
376378
}
377379
setIsExpandedInternal(!hidden);
380+
// We also need to collapse the space when the panel is hidden to prevent automation from scrolling to it
381+
if (hidden && ev.nativeEvent.propertyName === 'transform') {
382+
setShouldCollapseSpace(true);
383+
}
378384
if (isValidFocusTrap && ev.nativeEvent.propertyName === 'transform') {
379385
setIsFocusTrapActive((prevIsFocusTrapActive) => !prevIsFocusTrapActive);
380386
}
381387
}
382388
}}
383389
hidden={hidden}
384-
{...((defaultSize || minSize || maxSize) && {
385-
style: boundaryCssVars as React.CSSProperties
390+
{...((defaultSize || minSize || maxSize || shouldCollapseSpace) && {
391+
style: {
392+
...boundaryCssVars,
393+
...(shouldCollapseSpace && { flexBasis: 0 })
394+
} as React.CSSProperties
386395
})}
387396
{...props}
388397
ref={panel}

0 commit comments

Comments
 (0)