From 8bd56f08976b8629e851a7e46c528674d043316d Mon Sep 17 00:00:00 2001 From: Gavin <19986739+wjw-gavin@users.noreply.github.com> Date: Thu, 2 Feb 2023 23:33:47 +0800 Subject: [PATCH] fix(DatePicker): fix the value is not updated in time of change event (#11529) --- packages/vant/src/area/test/index.spec.ts | 3 ++- packages/vant/src/picker/Picker.tsx | 4 +++- packages/vant/src/picker/test/index.spec.tsx | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/vant/src/area/test/index.spec.ts b/packages/vant/src/area/test/index.spec.ts index 7730357e4..97b74b153 100644 --- a/packages/vant/src/area/test/index.spec.ts +++ b/packages/vant/src/area/test/index.spec.ts @@ -54,7 +54,7 @@ test('should watch modelValue prop and render correctly', async () => { ).toMatchSnapshot(); }); -test('should emit change event after dragging options', () => { +test('should emit change event after dragging options', async () => { const wrapper = mount(Area, { props: { areaList, @@ -67,6 +67,7 @@ test('should emit change event after dragging options', () => { triggerDrag(columns[2], 0, -100); columns[2].find('ul').trigger('transitionend'); + await later(); const params = wrapper.emitted('change')?.[0]; expect(params?.[0].selectedValues).toEqual(['120000', '120100', '120101']); }); diff --git a/packages/vant/src/picker/Picker.tsx b/packages/vant/src/picker/Picker.tsx index 4cf5f11b8..1555d9c39 100644 --- a/packages/vant/src/picker/Picker.tsx +++ b/packages/vant/src/picker/Picker.tsx @@ -160,7 +160,9 @@ export default defineComponent({ }); } - emit('change', extend({ columnIndex }, getEventParams())); + nextTick(() => { + emit('change', extend({ columnIndex }, getEventParams())); + }); }; const onClickOption = (currentOption: PickerOption, columnIndex: number) => diff --git a/packages/vant/src/picker/test/index.spec.tsx b/packages/vant/src/picker/test/index.spec.tsx index 87fe78c7d..a3d718436 100644 --- a/packages/vant/src/picker/test/index.spec.tsx +++ b/packages/vant/src/picker/test/index.spec.tsx @@ -46,7 +46,7 @@ test('should emit cancel event after clicking the cancel button', () => { ]); }); -test('should emit change event after draging the column', () => { +test('should emit change event after draging the column', async () => { const wrapper = mount(Picker, { props: { columns: simpleColumn, @@ -54,7 +54,7 @@ test('should emit change event after draging the column', () => { }); triggerDrag(wrapper.find('.van-picker-column'), 0, -100); - wrapper.find('.van-picker-column ul').trigger('transitionend'); + await wrapper.find('.van-picker-column ul').trigger('transitionend'); expect(wrapper.emitted('change')).toEqual([ [