Skip to content

Commit 378493b

Browse files
authored
fix: destroyOnClose should also works on inline mode (#281)
* test: test driven * fix: inline should also support destroyOnClose
1 parent 9bf5615 commit 378493b

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

src/Drawer.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ const Drawer: React.FC<DrawerProps> = props => {
4040
};
4141

4242
// ============================ Render ============================
43+
if (!forceRender && !animatedVisible && !open && destroyOnClose) {
44+
return null;
45+
}
46+
4347
const sharedDrawerProps = {
4448
...props,
4549
prefixCls,
@@ -50,10 +54,6 @@ const Drawer: React.FC<DrawerProps> = props => {
5054
return <DrawerPopup {...sharedDrawerProps} inline />;
5155
}
5256

53-
if (!forceRender && !animatedVisible && !open && destroyOnClose) {
54-
return null;
55-
}
56-
5757
return (
5858
<Portal
5959
visible={open}

tests/index.spec.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,23 @@ describe('rc-drawer-menu', () => {
159159
render(<Drawer forceRender />);
160160
expect(document.querySelector('.rc-drawer')).toBeTruthy();
161161
});
162-
it('destroyOnClose', () => {
163-
const { rerender } = render(<Drawer destroyOnClose open />);
164-
expect(document.querySelector('.rc-drawer')).toBeTruthy();
165-
rerender(<Drawer destroyOnClose />);
166-
expect(document.querySelector('.rc-drawer')).toBeFalsy();
162+
163+
describe('destroyOnClose', () => {
164+
it('basic', () => {
165+
const { rerender } = render(<Drawer destroyOnClose open />);
166+
expect(document.querySelector('.rc-drawer')).toBeTruthy();
167+
rerender(<Drawer destroyOnClose />);
168+
expect(document.querySelector('.rc-drawer')).toBeFalsy();
169+
});
170+
171+
it('inline', () => {
172+
const { container, rerender } = render(
173+
<Drawer destroyOnClose open getContainer={false} />,
174+
);
175+
expect(container.querySelector('.rc-drawer')).toBeTruthy();
176+
rerender(<Drawer destroyOnClose getContainer={false} />);
177+
expect(container.querySelector('.rc-drawer')).toBeFalsy();
178+
});
167179
});
168180

169181
describe('placement', () => {

0 commit comments

Comments
 (0)