Skip to content

Commit

Permalink
Merge pull request #2 from materialr/fix/close-behaviour
Browse files Browse the repository at this point in the history
fix: close behaviour now more consistent
  • Loading branch information
hvolschenk committed Nov 22, 2017
2 parents 7d8cd86 + 1fee093 commit a318e2f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Dialog extends React.Component {
this.focusTrap = undefined;
this.root = undefined;
this.surface = undefined;
this.dialogFoundationClose = this.dialogFoundationClose.bind(this);
this.dialogFoundationCreate = this.dialogFoundationCreate.bind(this);
this.dialogFoundationDestroy = this.dialogFoundationDestroy.bind(this);
this.dialogFoundationOpen = this.dialogFoundationOpen.bind(this);
Expand All @@ -43,7 +44,7 @@ class Dialog extends React.Component {
this.dialogFoundationOpen();
}
if (!visible && wasVisible) {
this.dialogFoundationDestroy();
this.dialogFoundationClose();
}
}
componentWillUnmount() {
Expand All @@ -68,6 +69,9 @@ class Dialog extends React.Component {
'mdc-dialog--theme-dark': this.props.dark,
});
}
dialogFoundationClose() {
this.dialogFoundation.close();
}
dialogFoundationCreate() {
const { onAccept, onCancel } = this.props;
this.dialogFoundation = dialogFoundation({
Expand Down
8 changes: 4 additions & 4 deletions src/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ test('Dialog > Opens when the \'visible\' prop becomes \'true\'', () => {
});

test('Dialog > Closes when the \'visible\' prop becomes \'false\'', () => {
const destroy = jest.fn();
const close = jest.fn();
const wrapper = mount(<Dialog {...defaultProps} visible />);
wrapper.instance().dialogFoundation.destroy = destroy;
wrapper.instance().dialogFoundation.close = close;
wrapper.setProps({ visible: false });
const expected = 1;

const actual = destroy.mock.calls.length;
const actual = close.mock.calls.length;

expect(actual).toBe(expected);
});
Expand All @@ -148,7 +148,7 @@ test('Dialog > Closes when the component unmounts', () => {
test('Dialog > Removes the foundation after destroying', () => {
const wrapper = mount(<Dialog {...defaultProps} visible />);
const expected = undefined;
wrapper.setProps({ visible: false });
wrapper.instance().dialogFoundationDestroy();

const actual = wrapper.instance().dialogFoundation;

Expand Down

0 comments on commit a318e2f

Please sign in to comment.