Skip to content

fix: Patch width / height size on the wrapper instead #282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/examples/base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const Demo = () => {
console.log('transitionEnd: ', c);
}}
placement="right"
width={400}
// width={400}
width="60%"
// Motion
{...motionProps}
>
Expand Down
23 changes: 1 addition & 22 deletions src/DrawerPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as React from 'react';
import classNames from 'classnames';
import type { Placement } from './Drawer';

export interface DrawerPanelRef {
focus: VoidFunction;
Expand All @@ -10,40 +9,20 @@ export interface DrawerPanelProps {
prefixCls: string;
className?: string;
style?: React.CSSProperties;
width?: number | string;
height?: number | string;
placement: Placement;
children?: React.ReactNode;
containerRef?: React.Ref<HTMLDivElement>;
}

const DrawerPanel = (props: DrawerPanelProps) => {
const {
prefixCls,
className,
style,
placement,
width,
height,
children,
containerRef,
} = props;
const { prefixCls, className, style, children, containerRef } = props;

// =============================== Render ===============================
const panelStyle: React.CSSProperties = {};

if (placement === 'left' || placement === 'right') {
panelStyle.width = width;
} else {
panelStyle.height = height;
}

return (
<>
<div
className={classNames(`${prefixCls}-content`, className)}
style={{
...panelStyle,
...style,
}}
aria-modal="true"
Expand Down
10 changes: 7 additions & 3 deletions src/DrawerPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,20 @@ export default function DrawerPopup(props: DrawerPopupProps) {
break;
case 'left':
wrapperStyle.transform = `translateX(${pushDistance}px)`;

break;
default:
wrapperStyle.transform = `translateX(${-pushDistance}px)`;
break;
}
}

if (placement === 'left' || placement === 'right') {
wrapperStyle.width = width;
} else {
wrapperStyle.height = height;
}

const panelNode: React.ReactNode = (
<div
className={classNames(`${prefixCls}-content-wrapper`)}
Expand Down Expand Up @@ -293,9 +300,6 @@ export default function DrawerPopup(props: DrawerPopupProps) {
...motionStyle,
...style,
}}
width={width}
height={height}
placement={placement}
>
{children}
</DrawerPanel>
Expand Down
10 changes: 10 additions & 0 deletions tests/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,14 @@ describe('rc-drawer-menu', () => {
zIndex: 93,
});
});

it('width on the correct element', () => {
const { container } = render(
<Drawer width="93%" open getContainer={false} />,
);

expect(container.querySelector('.rc-drawer-content-wrapper')).toHaveStyle({
width: '93%',
});
});
});
33 changes: 0 additions & 33 deletions tests/index.tsx

This file was deleted.