Skip to content

Commit 85040f8

Browse files
authored
fix: Patch width / height size on the wrapper instead (#282)
* fix: drawer ptg size * test: test case cov
1 parent 838e21d commit 85040f8

File tree

5 files changed

+20
-59
lines changed

5 files changed

+20
-59
lines changed

docs/examples/base.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ const Demo = () => {
2727
console.log('transitionEnd: ', c);
2828
}}
2929
placement="right"
30-
width={400}
30+
// width={400}
31+
width="60%"
3132
// Motion
3233
{...motionProps}
3334
>

src/DrawerPanel.tsx

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as React from 'react';
22
import classNames from 'classnames';
3-
import type { Placement } from './Drawer';
43

54
export interface DrawerPanelRef {
65
focus: VoidFunction;
@@ -10,40 +9,20 @@ export interface DrawerPanelProps {
109
prefixCls: string;
1110
className?: string;
1211
style?: React.CSSProperties;
13-
width?: number | string;
14-
height?: number | string;
15-
placement: Placement;
1612
children?: React.ReactNode;
1713
containerRef?: React.Ref<HTMLDivElement>;
1814
}
1915

2016
const DrawerPanel = (props: DrawerPanelProps) => {
21-
const {
22-
prefixCls,
23-
className,
24-
style,
25-
placement,
26-
width,
27-
height,
28-
children,
29-
containerRef,
30-
} = props;
17+
const { prefixCls, className, style, children, containerRef } = props;
3118

3219
// =============================== Render ===============================
33-
const panelStyle: React.CSSProperties = {};
34-
35-
if (placement === 'left' || placement === 'right') {
36-
panelStyle.width = width;
37-
} else {
38-
panelStyle.height = height;
39-
}
4020

4121
return (
4222
<>
4323
<div
4424
className={classNames(`${prefixCls}-content`, className)}
4525
style={{
46-
...panelStyle,
4726
...style,
4827
}}
4928
aria-modal="true"

src/DrawerPopup.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,20 @@ export default function DrawerPopup(props: DrawerPopupProps) {
253253
break;
254254
case 'left':
255255
wrapperStyle.transform = `translateX(${pushDistance}px)`;
256+
256257
break;
257258
default:
258259
wrapperStyle.transform = `translateX(${-pushDistance}px)`;
259260
break;
260261
}
261262
}
262263

264+
if (placement === 'left' || placement === 'right') {
265+
wrapperStyle.width = width;
266+
} else {
267+
wrapperStyle.height = height;
268+
}
269+
263270
const panelNode: React.ReactNode = (
264271
<div
265272
className={classNames(`${prefixCls}-content-wrapper`)}
@@ -293,9 +300,6 @@ export default function DrawerPopup(props: DrawerPopupProps) {
293300
...motionStyle,
294301
...style,
295302
}}
296-
width={width}
297-
height={height}
298-
placement={placement}
299303
>
300304
{children}
301305
</DrawerPanel>

tests/index.spec.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,4 +309,14 @@ describe('rc-drawer-menu', () => {
309309
zIndex: 93,
310310
});
311311
});
312+
313+
it('width on the correct element', () => {
314+
const { container } = render(
315+
<Drawer width="93%" open getContainer={false} />,
316+
);
317+
318+
expect(container.querySelector('.rc-drawer-content-wrapper')).toHaveStyle({
319+
width: '93%',
320+
});
321+
});
312322
});

tests/index.tsx

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)