Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix] Dialog: beforeClose not work for click overlay #2707

Merged
merged 3 commits into from Feb 9, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/dialog/Dialog.js
Expand Up @@ -41,8 +41,13 @@ export default sfc({
},

methods: {
onClickOverlay() {
this.handleAction('overlay');
},

handleAction(action) {
this.$emit(action);

if (this.beforeClose) {
this.loading[action] = true;
this.beforeClose(action, state => {
Expand All @@ -57,8 +62,11 @@ export default sfc({
},

onClose(action) {
this.$emit('input', false);
this.callback && this.callback(action);
this.close();

if (this.callback) {
this.callback(action);
}
}
},

Expand Down
16 changes: 13 additions & 3 deletions packages/dialog/test/index.spec.js
@@ -1,7 +1,7 @@
import Vue from 'vue';
import Dialog from '..';
import DialogVue from '../Dialog';
import { mount, later, transitionStub } from '../../../test/utils';
import { mount, later, trigger, transitionStub } from '../../../test/utils';

transitionStub();

Expand Down Expand Up @@ -39,6 +39,7 @@ test('before close', () => {
propsData: {
value: true,
showCancelButton: true,
closeOnClickOverlay: true,
beforeClose: (action, done) => done(false)
}
});
Expand All @@ -49,10 +50,19 @@ test('before close', () => {
expect(wrapper.emitted('input')).toBeFalsy();

wrapper.setProps({
beforeClose: (action, done) => done()
beforeClose: (action, done) => {
if (action === 'cancel') {
done();
}
}
});

const overlay = document.querySelector('.van-overlay');
trigger(overlay, 'click');
expect(wrapper.emitted('input')).toBeFalsy();

cancel.trigger('click');
expect(wrapper.emitted('input')).toBeTruthy();
expect(wrapper.emitted('input')[0]).toBeTruthy();
});

test('set default options', () => {
Expand Down
9 changes: 8 additions & 1 deletion packages/mixins/popup/manager.js
Expand Up @@ -63,7 +63,14 @@ export default {
if (context.top) {
const { vm } = context.top;
vm.$emit('click-overlay');
vm.closeOnClickOverlay && vm.$emit('input', false);

if (vm.closeOnClickOverlay) {
if (vm.onClickOverlay) {
vm.onClickOverlay();
} else {
vm.close();
}
}
}
}
};