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
52 changes: 39 additions & 13 deletions components/drawer/__tests__/MultiDrawer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import Drawer from '..';
import Button from '../../button';

class MultiDrawer extends React.Component {
state = { visible: false, childrenDrawer: false };
state = { visible: false, childrenDrawer: false, hasChildren: true };

showDrawer = () => {
this.setState({
visible: true,
hasChildren: true,
});
};

Expand All @@ -21,6 +22,7 @@ class MultiDrawer extends React.Component {
showChildrenDrawer = () => {
this.setState({
childrenDrawer: true,
hasChildren: true,
});
};

Expand All @@ -30,14 +32,23 @@ class MultiDrawer extends React.Component {
});
};

onRemoveChildDrawer = () => {
this.setState({
hasChildren: false,
});
};

render() {
const { childrenDrawer, visible } = this.state;
const { childrenDrawer, visible, hasChildren } = this.state;
const { placement } = this.props;
return (
<div>
<Button type="primary" id="open_drawer" onClick={this.showDrawer}>
Open drawer
</Button>
<Button type="primary" id="remove_drawer" onClick={this.onRemoveChildDrawer}>
rm child drawer
</Button>
<Drawer
title="Multi-level drawer"
className="test_drawer"
Expand All @@ -50,17 +61,19 @@ class MultiDrawer extends React.Component {
<Button type="primary" id="open_two_drawer" onClick={this.showChildrenDrawer}>
Two-level drawer
</Button>
<Drawer
title="Two-level Drawer"
width={320}
className="Two-level"
getContainer={false}
placement={placement}
onClose={this.onChildrenDrawerClose}
visible={childrenDrawer}
>
<div id="two_drawer_text">This is two-level drawer</div>
</Drawer>
{hasChildren && (
<Drawer
title="Two-level Drawer"
width={320}
className="Two-level"
getContainer={false}
placement={placement}
onClose={this.onChildrenDrawerClose}
visible={childrenDrawer}
>
<div id="two_drawer_text">This is two-level drawer</div>
</Drawer>
)}
<div
style={{
position: 'absolute',
Expand Down Expand Up @@ -121,4 +134,17 @@ describe('Drawer', () => {
expect(translateX).toEqual('translateY(180px)');
expect(wrapper.find('#two_drawer_text').exists()).toBe(true);
});

it('render MultiDrawer is child in unmount', () => {
const wrapper = mount(<MultiDrawer placement="top" mask={false} />);
wrapper.find('button#open_drawer').simulate('click');
wrapper.find('button#open_two_drawer').simulate('click');
wrapper.find('button#remove_drawer').simulate('click');
let translateX = wrapper.find('.ant-drawer.test_drawer').get(0).props.style.transform;
expect(translateX).toEqual(undefined);
wrapper.find('button#open_two_drawer').simulate('click');
translateX = wrapper.find('.ant-drawer.test_drawer').get(0).props.style.transform;
expect(translateX).toEqual('translateY(180px)');
expect(wrapper.find('#two_drawer_text').exists()).toBe(true);
});
});
22 changes: 20 additions & 2 deletions components/drawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,19 @@ class Drawer extends React.Component<DrawerProps & ConfigConsumerProps, IDrawerS
push: false,
};

parentDrawer: Drawer;
parentDrawer: Drawer | null;

destroyClose: boolean;

public componentDidMount() {
// fix: delete drawer in child and re-render, no push started.
// <Drawer>{show && <Drawer />}</Drawer>
const { visible } = this.props;
if (visible && this.parentDrawer) {
this.parentDrawer.push();
}
}

public componentDidUpdate(preProps: DrawerProps) {
const { visible } = this.props;
if (preProps.visible !== visible && this.parentDrawer) {
Expand All @@ -77,6 +87,14 @@ class Drawer extends React.Component<DrawerProps & ConfigConsumerProps, IDrawerS
}
}

public componentWillUnmount() {
// unmount drawer in child, clear push.
if (this.parentDrawer) {
this.parentDrawer.pull();
this.parentDrawer = null;
}
}

push = () => {
this.setState({
push: true,
Expand Down Expand Up @@ -186,7 +204,7 @@ class Drawer extends React.Component<DrawerProps & ConfigConsumerProps, IDrawerS
);
};

// render Provider for Multi-level drawe
// render Provider for Multi-level drawer
renderProvider = (value: Drawer) => {
const {
prefixCls,
Expand Down
7 changes: 3 additions & 4 deletions components/drawer/style/drawer.less
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
z-index: @zindex-modal;
width: 0%;
height: 100%;

transition: transform @animation-duration-slow @ease-base-out;
> * {
transition: transform @animation-duration-slow @ease-base-in,
box-shadow @animation-duration-slow @ease-base-in;
transition: transform @animation-duration-slow @ease-base-out,
box-shadow @animation-duration-slow @ease-base-out;
}

&-content-wrapper {
Expand Down Expand Up @@ -197,7 +197,6 @@
transition: opacity @animation-duration-slow linear, height 0s ease @animation-duration-slow;
}
&-open {
transition: transform @animation-duration-slow @ease-base-out;
&-content {
box-shadow: @shadow-2;
}
Expand Down