Skip to content

Commit fb91a1d

Browse files
authored
fix(DrawerPanelContent): fix issue with styles overriding (#12039)
* fix(DrawerPanelContent): fix issue with styles overriding Signed-off-by: gitdallas <5322142+gitdallas@users.noreply.github.com> * added tests Signed-off-by: gitdallas <5322142+gitdallas@users.noreply.github.com> --------- Signed-off-by: gitdallas <5322142+gitdallas@users.noreply.github.com>
1 parent 0cdf0e5 commit fb91a1d

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export const DrawerPanelContent: React.FunctionComponent<DrawerPanelContentProps
7777
widths,
7878
colorVariant = DrawerColorVariant.default,
7979
focusTrap,
80+
style,
8081
...props
8182
}: DrawerPanelContentProps) => {
8283
const panel = useRef<HTMLDivElement>(undefined);
@@ -381,9 +382,10 @@ export const DrawerPanelContent: React.FunctionComponent<DrawerPanelContentProps
381382
}
382383
}}
383384
hidden={hidden}
384-
{...((defaultSize || minSize || maxSize) && {
385-
style: boundaryCssVars as React.CSSProperties
386-
})}
385+
style={{
386+
...((defaultSize || minSize || maxSize) && boundaryCssVars),
387+
...style
388+
}}
387389
{...props}
388390
ref={panel}
389391
>

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,40 @@ test('Renders with role="dialog" when focusTrap.enabled is true', () => {
121121

122122
expect(screen.getByRole('dialog')).toBeInTheDocument();
123123
});
124+
125+
test('Applies style prop as expected', () => {
126+
render(
127+
<Drawer isExpanded>
128+
<DrawerPanelContent style={{ backgroundColor: 'red', padding: '20px' }}>Drawer panel content</DrawerPanelContent>
129+
</Drawer>
130+
);
131+
132+
const panelContent = screen.getByText('Drawer panel content');
133+
expect(panelContent).toHaveStyle({ backgroundColor: 'red', padding: '20px' });
134+
});
135+
136+
test('Style prop overrides boundaryCssVars', () => {
137+
render(
138+
<Drawer isExpanded>
139+
<DrawerPanelContent
140+
defaultSize="200px"
141+
minSize="100px"
142+
maxSize="400px"
143+
style={{
144+
'--pf-v6-c-drawer__panel--md--FlexBasis': '300px',
145+
'--pf-v6-c-drawer__panel--md--FlexBasis--min': '150px',
146+
'--pf-v6-c-drawer__panel--md--FlexBasis--max': '500px'
147+
}}
148+
>
149+
Drawer panel content
150+
</DrawerPanelContent>
151+
</Drawer>
152+
);
153+
154+
const panelContent = screen.getByText('Drawer panel content');
155+
expect(panelContent).toHaveStyle({
156+
'--pf-v6-c-drawer__panel--md--FlexBasis': '300px',
157+
'--pf-v6-c-drawer__panel--md--FlexBasis--min': '150px',
158+
'--pf-v6-c-drawer__panel--md--FlexBasis--max': '500px'
159+
});
160+
});

0 commit comments

Comments
 (0)