Skip to content
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
22 changes: 19 additions & 3 deletions src/DrawerPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<DrawerContextProps>(
() => ({
Expand Down
28 changes: 28 additions & 0 deletions tests/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,34 @@ describe('rc-drawer-menu', () => {
});
});
});

it('disable push', () => {
const { container } = render(
<Drawer push={false} open getContainer={false}>
<Drawer open />
</Drawer>,
);

expect(container.querySelector('.rc-drawer-content-wrapper')).toHaveStyle(
{
transform: '',
},
);
});

it('truthy', () => {
const { container } = render(
<Drawer push open getContainer={false}>
<Drawer open />
</Drawer>,
);

expect(container.querySelector('.rc-drawer-content-wrapper')).toHaveStyle(
{
transform: 'translateX(-180px)',
},
);
});
});

describe('mask', () => {
Expand Down