diff --git a/src/DrawerPopup.tsx b/src/DrawerPopup.tsx index 72b27dc6..2829b036 100644 --- a/src/DrawerPopup.tsx +++ b/src/DrawerPopup.tsx @@ -10,11 +10,15 @@ import type { DrawerContextProps } from './context'; export type Placement = 'left' | 'right' | 'top' | 'bottom'; +export interface PushConfig { + distance?: number | string; +} + export interface DrawerPopupProps { prefixCls: string; open?: boolean; inline?: boolean; - push?: { distance?: number | string }; + push?: boolean | PushConfig; forceRender?: boolean; autoFocus?: boolean; keyboard?: boolean; @@ -94,11 +98,23 @@ export default function DrawerPopup(props: DrawerPopupProps) { } = props; // ============================ Push ============================ - const { distance } = push || {}; const [pushed, setPushed] = React.useState(false); const parentContext = React.useContext(DrawerContext); - const pushDistance = distance ?? parentContext?.pushDistance ?? 180; + + // Merge push distance + let pushConfig: PushConfig; + if (push === false) { + pushConfig = { + distance: 0, + }; + } else if (push === true) { + pushConfig = {}; + } else { + pushConfig = push || {}; + } + const pushDistance = + pushConfig?.distance ?? parentContext?.pushDistance ?? 180; const mergedContext = React.useMemo( () => ({ diff --git a/tests/index.spec.tsx b/tests/index.spec.tsx index 95badd42..0b9faae9 100755 --- a/tests/index.spec.tsx +++ b/tests/index.spec.tsx @@ -91,6 +91,34 @@ describe('rc-drawer-menu', () => { }); }); }); + + it('disable push', () => { + const { container } = render( + + + , + ); + + expect(container.querySelector('.rc-drawer-content-wrapper')).toHaveStyle( + { + transform: '', + }, + ); + }); + + it('truthy', () => { + const { container } = render( + + + , + ); + + expect(container.querySelector('.rc-drawer-content-wrapper')).toHaveStyle( + { + transform: 'translateX(-180px)', + }, + ); + }); }); describe('mask', () => {