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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ ReactDOM.render(
<td></td>
<td>to determine where Dialog will be mounted</td>
</tr>
<tr>
<td>destroyOnHide</td>
<td>Boolean</td>
<td>false</td>
<td>to unmount child compenents on onClose</td>
</tr>
</tbody>
</table>

Expand Down
3 changes: 2 additions & 1 deletion src/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export default class Dialog extends React.Component<IDialogPropTypes, any> {
keyboard: true,
closable: true,
maskClosable: true,
destroyOnHide: false,
prefixCls: 'rc-dialog',
};

Expand Down Expand Up @@ -234,7 +235,7 @@ export default class Dialog extends React.Component<IDialogPropTypes, any> {
component=""
transitionAppear
>
{dialogElement}
{(props.visible || !props.destroyOnHide) ? dialogElement : null}
</Animate>
);
}
Expand Down
1 change: 1 addition & 0 deletions src/IDialogPropTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface IDialogPropTypes {
closable?: boolean;
maskClosable?: boolean;
visible?: boolean;
destroyOnHide ?: boolean;
mousePosition?: {
x: number,
y: number,
Expand Down
18 changes: 18 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,24 @@ describe('dialog', () => {
}], finish);
});

it("destroy on hide should unmount child components on close", () => {
const wrapper = ReactDOM.render(<DialogWrap destroyOnHide>
<input className="inputElem" />
</DialogWrap>, container);
wrapper.setState({
visible: true,
});
$(".inputElem").val("test");
expect($(".inputElem").val()).to.be("test")
wrapper.setState({
visible: false,
});
wrapper.setState({
visible: true,
});
expect($(".inputElem").val()).to.be("")
})

it('esc to close', (finish) => {
async.series([(done) => {
dialog.setState({
Expand Down