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
2 changes: 1 addition & 1 deletion docs/examples/forceRender.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default () => {
width="20vw"
open={open2}
onClose={() => setOpen2(false)}
destroyOnClose
destroyOnHidden
placement="left"
{...motionProps}
>
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"@testing-library/react": "^14.0.0",
"@types/classnames": "^2.2.9",
"@types/jest": "^29.5.11",
"@types/node": "^22.15.18",
"@types/raf": "^3.4.0",
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0",
Expand Down
14 changes: 5 additions & 9 deletions src/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface DrawerProps
prefixCls?: string;
open?: boolean;
onClose?: (e: React.MouseEvent | React.KeyboardEvent) => void;
destroyOnClose?: boolean;
destroyOnHidden?: boolean;
getContainer?: PortalProps['getContainer'];
panelRef?: React.Ref<HTMLDivElement>;
classNames?: DrawerClassNames;
Expand All @@ -41,7 +41,7 @@ const Drawer: React.FC<DrawerProps> = props => {
getContainer,
forceRender,
afterOpenChange,
destroyOnClose,
destroyOnHidden,
onMouseEnter,
onMouseOver,
onMouseLeave,
Expand Down Expand Up @@ -95,15 +95,10 @@ const Drawer: React.FC<DrawerProps> = props => {
};

// =========================== Context ============================
const refContext = React.useMemo(
() => ({
panel: panelRef,
}),
[panelRef],
);
const refContext = React.useMemo(() => ({ panel: panelRef }), [panelRef]);

// ============================ Render ============================
if (!forceRender && !animatedVisible && !mergedOpen && destroyOnClose) {
if (!forceRender && !animatedVisible && !mergedOpen && destroyOnHidden) {
return null;
}

Expand All @@ -115,6 +110,7 @@ const Drawer: React.FC<DrawerProps> = props => {
onKeyDown,
onKeyUp,
};

const drawerPopupProps = {
...props,
open: mergedOpen,
Expand Down
2 changes: 1 addition & 1 deletion src/DrawerPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface DrawerPanelProps
containerRef?: React.Ref<HTMLDivElement>;
}

const DrawerPanel = (props: DrawerPanelProps) => {
const DrawerPanel: React.FC<Readonly<DrawerPanelProps>> = props => {
const { prefixCls, className, containerRef, ...restProps } = props;

const { panel: panelRef } = React.useContext(RefContext);
Expand Down
7 changes: 5 additions & 2 deletions src/DrawerPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ export interface DrawerPopupProps
drawerRender?: (node: React.ReactNode) => React.ReactNode;
}

function DrawerPopup(props: DrawerPopupProps, ref: React.Ref<HTMLDivElement>) {
const DrawerPopup: React.ForwardRefRenderFunction<
HTMLDivElement,
DrawerPopupProps
> = (props, ref) => {
const {
prefixCls,
open,
Expand Down Expand Up @@ -375,7 +378,7 @@ function DrawerPopup(props: DrawerPopupProps, ref: React.Ref<HTMLDivElement>) {
</div>
</DrawerContext.Provider>
);
}
};

const RefDrawerPopup = React.forwardRef(DrawerPopup);

Expand Down
10 changes: 5 additions & 5 deletions tests/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,20 +183,20 @@ describe('rc-drawer-menu', () => {
expect(document.querySelector('.rc-drawer')).toBeTruthy();
});

describe('destroyOnClose', () => {
describe('destroyOnHidden', () => {
it('basic', () => {
const { rerender } = render(<Drawer destroyOnClose open />);
const { rerender } = render(<Drawer destroyOnHidden open />);
expect(document.querySelector('.rc-drawer')).toBeTruthy();
rerender(<Drawer destroyOnClose />);
rerender(<Drawer destroyOnHidden />);
expect(document.querySelector('.rc-drawer')).toBeFalsy();
});

it('inline', () => {
const { container, rerender } = render(
<Drawer destroyOnClose open getContainer={false} />,
<Drawer destroyOnHidden open getContainer={false} />,
);
expect(container.querySelector('.rc-drawer')).toBeTruthy();
rerender(<Drawer destroyOnClose getContainer={false} />);
rerender(<Drawer destroyOnHidden getContainer={false} />);
expect(container.querySelector('.rc-drawer')).toBeFalsy();
});
});
Expand Down