Skip to content

Commit 7354e16

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 7354e16

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-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}

packages/react-core/src/components/Drawer/__tests__/Generated/__snapshots__/DrawerPanelContent.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ exports[`DrawerPanelContent should match snapshot (auto-generated) 1`] = `
66
class="pf-v6-c-drawer__panel ''"
77
hidden=""
88
id="generated-id"
9+
style="flex-basis: 0px;"
910
/>
1011
</DocumentFragment>
1112
`;

packages/react-core/src/components/Drawer/__tests__/__snapshots__/Drawer.test.tsx.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ exports[`Drawer isExpanded = false and isInline = false and isStatic = false 1`]
281281
class="pf-v6-c-drawer__panel"
282282
hidden=""
283283
id="generated-id"
284+
style="flex-basis: 0px;"
284285
/>
285286
</div>
286287
</div>
@@ -308,6 +309,7 @@ exports[`Drawer isExpanded = false and isInline = true and isStatic = false 1`]
308309
class="pf-v6-c-drawer__panel"
309310
hidden=""
310311
id="generated-id"
312+
style="flex-basis: 0px;"
311313
/>
312314
</div>
313315
</div>

0 commit comments

Comments
 (0)