diff --git a/src/Drawer.tsx b/src/Drawer.tsx index 7e00da59..e8ee54e6 100644 --- a/src/Drawer.tsx +++ b/src/Drawer.tsx @@ -10,40 +10,26 @@ export type Placement = 'left' | 'top' | 'right' | 'bottom'; export interface DrawerProps extends Omit { prefixCls?: string; - open?: boolean; onClose?: (e: React.MouseEvent | React.KeyboardEvent) => void; destroyOnClose?: boolean; getContainer?: PortalProps['getContainer']; } -// Default Value. -// Since spread with default value will make this all over components. -// Let's maintain this in one place. -const defaultProps = { - open: false, - prefixCls: 'rc-drawer', - placement: 'right' as Placement, - autoFocus: true, - keyboard: true, - width: 378, - mask: true, - maskClosable: true, -}; - -const Drawer: React.FC = drawerProps => { - const props = { - ...defaultProps, - ...drawerProps, - }; +const Drawer: React.FC = props => { const { - open, + open = false, + prefixCls = 'rc-drawer', + placement = 'right' as Placement, + autoFocus = true, + keyboard = true, + width = 378, + mask = true, + maskClosable = true, getContainer, forceRender, - prefixCls, afterOpenChange, destroyOnClose, - mask, } = props; const [animatedVisible, setAnimatedVisible] = React.useState(false); @@ -65,9 +51,17 @@ const Drawer: React.FC = drawerProps => { return null; } - const sharedDrawerProps = { + const drawerPopupProps = { ...props, + open, prefixCls, + placement, + autoFocus, + keyboard, + width, + mask, + maskClosable, + inline: getContainer === false, afterOpenChange: internalAfterOpenChange, }; @@ -78,7 +72,7 @@ const Drawer: React.FC = drawerProps => { getContainer={getContainer} autoLock={mask && (open || animatedVisible)} > - + ); }; diff --git a/tests/index.spec.tsx b/tests/index.spec.tsx index 6a901def..3532b56c 100755 --- a/tests/index.spec.tsx +++ b/tests/index.spec.tsx @@ -40,6 +40,22 @@ describe('rc-drawer-menu', () => { ).toBeTruthy(); }); + it('default props should work', () => { + const { container, unmount } = render( + , + ); + expect(container.querySelector('.rc-drawer-right')).toBeTruthy(); + expect( + container.querySelector('.rc-drawer-content-wrapper').style.width, + ).toBe('378px'); + unmount(); + }); + describe('push', () => { const placementList: { placement: DrawerProps['placement'];