Skip to content

Commit 29aa1e5

Browse files
committed
fix(DrawerPanelContent): add inert when drawer is closed
1 parent ff397d8 commit 29aa1e5

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export const DrawerPanelContent: React.FunctionComponent<DrawerPanelContentProps
8787
const hidden = isStatic ? false : !isExpanded;
8888
const [isExpandedInternal, setIsExpandedInternal] = useState(!hidden);
8989
const [isFocusTrapActive, setIsFocusTrapActive] = useState(false);
90+
const [shouldCollapseSpace, setShouldCollapseSpace] = useState(hidden);
9091
const previouslyFocusedElement = useRef(null);
9192
let currWidth: number = 0;
9293
let panelRect: DOMRect;
@@ -105,6 +106,7 @@ export const DrawerPanelContent: React.FunctionComponent<DrawerPanelContentProps
105106
useEffect(() => {
106107
if (!isStatic && isExpanded) {
107108
setIsExpandedInternal(isExpanded);
109+
setShouldCollapseSpace(false);
108110
}
109111
}, [isStatic, isExpanded]);
110112

@@ -376,6 +378,10 @@ export const DrawerPanelContent: React.FunctionComponent<DrawerPanelContentProps
376378
onExpand(ev);
377379
}
378380
setIsExpandedInternal(!hidden);
381+
// We also need to collapse the space when the panel is hidden to prevent automation from scrolling to it
382+
if (hidden && ev.nativeEvent.propertyName === 'transform') {
383+
setShouldCollapseSpace(true);
384+
}
379385
if (isValidFocusTrap && ev.nativeEvent.propertyName === 'transform') {
380386
setIsFocusTrapActive((prevIsFocusTrapActive) => !prevIsFocusTrapActive);
381387
}
@@ -386,6 +392,7 @@ export const DrawerPanelContent: React.FunctionComponent<DrawerPanelContentProps
386392
...((defaultSize || minSize || maxSize) && boundaryCssVars),
387393
...style
388394
}}
395+
{...(shouldCollapseSpace && { inert: '' })}
389396
{...props}
390397
ref={panel}
391398
>

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+
inert=""
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+
inert=""
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+
inert=""
311313
/>
312314
</div>
313315
</div>

0 commit comments

Comments
 (0)