diff --git a/packages/vant/src/address-edit/AddressEdit.tsx b/packages/vant/src/address-edit/AddressEdit.tsx index 73ccb73b7..eec2212a3 100644 --- a/packages/vant/src/address-edit/AddressEdit.tsx +++ b/packages/vant/src/address-edit/AddressEdit.tsx @@ -95,6 +95,7 @@ export default defineComponent({ emits: [ 'save', 'focus', + 'change', 'delete', 'clickArea', 'changeArea', @@ -136,6 +137,10 @@ export default defineComponent({ emit('focus', key); }; + const onChange = (key: string, value: string) => { + emit('change', { key, value }); + }; + const rules = computed>(() => { const { validator, telValidator } = props; @@ -273,6 +278,7 @@ export default defineComponent({ rules={rules.value.name} placeholder={t('name')} onFocus={() => onFocus('name')} + onUpdate:modelValue={(val) => onChange('name', val)} /> onFocus('tel')} + onUpdate:modelValue={(val) => onChange('tel', val)} /> { expect(wrapper.emitted('changeDetail')).toEqual([['123']]); }); +test('should emit change event after name or tel input', () => { + const wrapper = mount(AddressEdit); + + const field = wrapper.findAll('.van-field__control')[0]; + (field.element as HTMLInputElement).value = '123'; + field.trigger('input'); + expect(wrapper.emitted('change')?.[0]).toEqual([ + { key: 'name', value: '123' }, + ]); + + const field1 = wrapper.findAll('.van-field__control')[1]; + (field1.element as HTMLInputElement).value = '123'; + field1.trigger('input'); + expect(wrapper.emitted('change')?.[1]).toEqual([ + { key: 'tel', value: '123' }, + ]); +}); + test('should show search result after focusing to address detail', async () => { const wrapper = mount(AddressEdit, { props: {