Skip to content

Commit 8928745

Browse files
authored
fix(DrawerPanelContent): add inert when drawer is closed (#12027)
1 parent 2767ce0 commit 8928745

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-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
@@ -90,6 +90,7 @@ export const DrawerPanelContent: React.FunctionComponent<DrawerPanelContentProps
9090
const hidden = isStatic ? false : !isExpanded;
9191
const [isExpandedInternal, setIsExpandedInternal] = useState(!hidden);
9292
const [isFocusTrapActive, setIsFocusTrapActive] = useState(false);
93+
const [shouldCollapseSpace, setShouldCollapseSpace] = useState(hidden);
9394
const previouslyFocusedElement = useRef(null);
9495
let currWidth: number = 0;
9596
let panelRect: DOMRect;
@@ -108,6 +109,7 @@ export const DrawerPanelContent: React.FunctionComponent<DrawerPanelContentProps
108109
useEffect(() => {
109110
if (!isStatic && isExpanded) {
110111
setIsExpandedInternal(isExpanded);
112+
setShouldCollapseSpace(false);
111113
}
112114
}, [isStatic, isExpanded]);
113115

@@ -380,6 +382,10 @@ export const DrawerPanelContent: React.FunctionComponent<DrawerPanelContentProps
380382
onExpand(ev);
381383
}
382384
setIsExpandedInternal(!hidden);
385+
// We also need to collapse the space when the panel is hidden to prevent automation from scrolling to it
386+
if (hidden && ev.nativeEvent.propertyName === 'transform') {
387+
setShouldCollapseSpace(true);
388+
}
383389
if (isValidFocusTrap && ev.nativeEvent.propertyName === 'transform') {
384390
setIsFocusTrapActive((prevIsFocusTrapActive) => !prevIsFocusTrapActive);
385391
}
@@ -390,6 +396,7 @@ export const DrawerPanelContent: React.FunctionComponent<DrawerPanelContentProps
390396
...((defaultSize || minSize || maxSize) && boundaryCssVars),
391397
...style
392398
}}
399+
{...(shouldCollapseSpace && { inert: '' })}
393400
{...props}
394401
ref={panel}
395402
>

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,26 @@ test('Renders with role="dialog" when focusTrap.enabled is true', () => {
122122
expect(screen.getByRole('dialog')).toBeInTheDocument();
123123
});
124124

125+
test('Does not render with inert when drawer is expanded', () => {
126+
render(
127+
<Drawer isExpanded>
128+
<DrawerPanelContent data-testid="drawer-content">Drawer panel content</DrawerPanelContent>
129+
</Drawer>
130+
);
131+
132+
expect(screen.getByTestId('drawer-content')).not.toHaveAttribute('inert');
133+
});
134+
135+
test('Renders with inert when drawer is collapsed', () => {
136+
render(
137+
<Drawer>
138+
<DrawerPanelContent data-testid="drawer-content">Drawer panel content</DrawerPanelContent>
139+
</Drawer>
140+
);
141+
142+
expect(screen.getByTestId('drawer-content')).toHaveAttribute('inert');
143+
});
144+
125145
test('Applies style prop as expected', () => {
126146
render(
127147
<Drawer isExpanded>

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)