mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[bugfix] Dialog: beforeClose not work for click overlay (#2707)
This commit is contained in:
parent
683e6d5183
commit
e64b908a32
@ -41,8 +41,13 @@ export default sfc({
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
onClickOverlay() {
|
||||||
|
this.handleAction('overlay');
|
||||||
|
},
|
||||||
|
|
||||||
handleAction(action) {
|
handleAction(action) {
|
||||||
this.$emit(action);
|
this.$emit(action);
|
||||||
|
|
||||||
if (this.beforeClose) {
|
if (this.beforeClose) {
|
||||||
this.loading[action] = true;
|
this.loading[action] = true;
|
||||||
this.beforeClose(action, state => {
|
this.beforeClose(action, state => {
|
||||||
@ -57,8 +62,11 @@ export default sfc({
|
|||||||
},
|
},
|
||||||
|
|
||||||
onClose(action) {
|
onClose(action) {
|
||||||
this.$emit('input', false);
|
this.close();
|
||||||
this.callback && this.callback(action);
|
|
||||||
|
if (this.callback) {
|
||||||
|
this.callback(action);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
import Dialog from '..';
|
import Dialog from '..';
|
||||||
import DialogVue from '../Dialog';
|
import DialogVue from '../Dialog';
|
||||||
import { mount, later, transitionStub } from '../../../test/utils';
|
import { mount, later, trigger, transitionStub } from '../../../test/utils';
|
||||||
|
|
||||||
transitionStub();
|
transitionStub();
|
||||||
|
|
||||||
@ -39,6 +39,7 @@ test('before close', () => {
|
|||||||
propsData: {
|
propsData: {
|
||||||
value: true,
|
value: true,
|
||||||
showCancelButton: true,
|
showCancelButton: true,
|
||||||
|
closeOnClickOverlay: true,
|
||||||
beforeClose: (action, done) => done(false)
|
beforeClose: (action, done) => done(false)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -49,10 +50,19 @@ test('before close', () => {
|
|||||||
expect(wrapper.emitted('input')).toBeFalsy();
|
expect(wrapper.emitted('input')).toBeFalsy();
|
||||||
|
|
||||||
wrapper.setProps({
|
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');
|
cancel.trigger('click');
|
||||||
expect(wrapper.emitted('input')).toBeTruthy();
|
expect(wrapper.emitted('input')[0]).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('set default options', () => {
|
test('set default options', () => {
|
||||||
|
@ -63,7 +63,14 @@ export default {
|
|||||||
if (context.top) {
|
if (context.top) {
|
||||||
const { vm } = context.top;
|
const { vm } = context.top;
|
||||||
vm.$emit('click-overlay');
|
vm.$emit('click-overlay');
|
||||||
vm.closeOnClickOverlay && vm.$emit('input', false);
|
|
||||||
|
if (vm.closeOnClickOverlay) {
|
||||||
|
if (vm.onClickOverlay) {
|
||||||
|
vm.onClickOverlay();
|
||||||
|
} else {
|
||||||
|
vm.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user