mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(Popup): close event emiited twice (#10132)
This commit is contained in:
parent
9c16f4240a
commit
7831553bee
@ -213,10 +213,11 @@ export default defineComponent({
|
|||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.show,
|
() => props.show,
|
||||||
(value) => {
|
(show) => {
|
||||||
if (value) {
|
if (show && !opened) {
|
||||||
open();
|
open();
|
||||||
} else {
|
}
|
||||||
|
if (!show && opened) {
|
||||||
opened = false;
|
opened = false;
|
||||||
emit('close');
|
emit('close');
|
||||||
}
|
}
|
||||||
|
@ -129,6 +129,22 @@ test('should emit close event when show prop is set to false', async () => {
|
|||||||
expect(onClose).toHaveBeenCalledTimes(1);
|
expect(onClose).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should emit close event after clicking the overlay', async () => {
|
||||||
|
const onClose = jest.fn();
|
||||||
|
wrapper = mount(Popup, {
|
||||||
|
props: {
|
||||||
|
show: true,
|
||||||
|
onClose,
|
||||||
|
'onUpdate:show': (show) => {
|
||||||
|
wrapper.setProps({ show });
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await wrapper.find('.van-overlay').trigger('click');
|
||||||
|
expect(onClose).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
test('should change duration when using duration prop', () => {
|
test('should change duration when using duration prop', () => {
|
||||||
wrapper = mount(Popup, {
|
wrapper = mount(Popup, {
|
||||||
props: {
|
props: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user