Skip to content

Commit

Permalink
fix: Patch width / height size on the wrapper instead (#282)
Browse files Browse the repository at this point in the history
* fix: drawer ptg size

* test: test case cov
  • Loading branch information
zombieJ authored Jul 27, 2022
1 parent 838e21d commit 85040f8
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 59 deletions.
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.

1 comment on commit 85040f8

@vercel
Copy link

@vercel vercel bot commented on 85040f8 Jul 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

drawer – ./

drawer-git-master-react-component.vercel.app
drawer-react-component.vercel.app
drawer.vercel.app

Please sign in to comment.