From 777d1d5dda817278119c67326e95a3de91f2c5a8 Mon Sep 17 00:00:00 2001 From: tanjinzhou <415800467@qq.com> Date: Tue, 28 Jul 2020 16:04:12 +0800 Subject: [PATCH] fix: checkbox focus & blur not work --- antdv-demo | 2 +- components/checkbox/__tests__/group.test.js | 45 +++++---------------- components/vc-checkbox/src/Checkbox.jsx | 12 +++--- examples/App.vue | 2 +- 4 files changed, 18 insertions(+), 43 deletions(-) diff --git a/antdv-demo b/antdv-demo index 156f6e903..46fbd8fd0 160000 --- a/antdv-demo +++ b/antdv-demo @@ -1 +1 @@ -Subproject commit 156f6e903435aff90e130518d80dd676fae22c5d +Subproject commit 46fbd8fd067c497a740594a1b8cc8e503fc94a8a diff --git a/components/checkbox/__tests__/group.test.js b/components/checkbox/__tests__/group.test.js index 80b40fadc..7756b42e9 100644 --- a/components/checkbox/__tests__/group.test.js +++ b/components/checkbox/__tests__/group.test.js @@ -17,25 +17,13 @@ describe('CheckboxGroup', () => { sync: false, }, ); - wrapper - .findAll('.ant-checkbox-input') - .at(0) - .trigger('change'); + wrapper.findAll('.ant-checkbox-input')[0].trigger('change'); expect(onChange).toHaveBeenCalledWith(['Apple']); - wrapper - .findAll('.ant-checkbox-input') - .at(1) - .trigger('change'); + wrapper.findAll('.ant-checkbox-input')[1].trigger('change'); expect(onChange).toHaveBeenCalledWith(['Apple', 'Pear']); - wrapper - .findAll('.ant-checkbox-input') - .at(2) - .trigger('change'); + wrapper.findAll('.ant-checkbox-input')[2].trigger('change'); expect(onChange).toHaveBeenCalledWith(['Apple', 'Pear', 'Orange']); - wrapper - .findAll('.ant-checkbox-input') - .at(1) - .trigger('change'); + wrapper.findAll('.ant-checkbox-input')[1].trigger('change'); expect(onChange).toHaveBeenCalledWith(['Apple', 'Orange']); }); @@ -57,15 +45,9 @@ describe('CheckboxGroup', () => { sync: false, }, ); - groupWrapper - .findAll('.ant-checkbox-input') - .at(0) - .trigger('change'); + groupWrapper.findAll('.ant-checkbox-input')[0].trigger('change'); expect(onChangeGroup).not.toBeCalled(); - groupWrapper - .findAll('.ant-checkbox-input') - .at(1) - .trigger('change'); + groupWrapper.findAll('.ant-checkbox-input')[1].trigger('change'); expect(onChangeGroup).not.toBeCalled(); }); @@ -87,15 +69,9 @@ describe('CheckboxGroup', () => { sync: false, }, ); - groupWrapper - .findAll('.ant-checkbox-input') - .at(0) - .trigger('change'); + groupWrapper.findAll('.ant-checkbox-input')[0].trigger('change'); expect(onChangeGroup).toHaveBeenCalledWith(['Apple']); - groupWrapper - .findAll('.ant-checkbox-input') - .at(1) - .trigger('change'); + groupWrapper.findAll('.ant-checkbox-input')[1].trigger('change'); expect(onChangeGroup).toHaveBeenCalledWith(['Apple']); }); @@ -143,10 +119,7 @@ describe('CheckboxGroup', () => { ); }, }); - wrapper - .findAll('.ant-checkbox-input') - .at(0) - .trigger('change'); + wrapper.findAll('.ant-checkbox-input')[0].trigger('change'); expect(onChange).toBeCalled(); expect(onChange.mock.calls[0][0].target.value).toEqual('my'); }); diff --git a/components/vc-checkbox/src/Checkbox.jsx b/components/vc-checkbox/src/Checkbox.jsx index c5141c47f..9c22a08e8 100644 --- a/components/vc-checkbox/src/Checkbox.jsx +++ b/components/vc-checkbox/src/Checkbox.jsx @@ -45,8 +45,10 @@ export default { }, mounted() { nextTick(() => { - if (this.autofocus) { - this.$refs.input && this.$refs.input.focus(); + if (process.env.NODE_ENV === 'test') { + if (this.autofocus) { + this.$refs.input && this.$refs.input.focus(); + } } }); }, @@ -103,12 +105,10 @@ export default { readonly, tabindex, autofocus, - onFocus, - onBlur, value, ...others } = getOptionProps(this); - const { class: className } = this.$attrs; + const { class: className, onFocus, onBlur } = this.$attrs; const globalProps = Object.keys({ ...others, ...this.$attrs }).reduce((prev, key) => { if (key.substr(0, 5) === 'aria-' || key.substr(0, 5) === 'data-' || key === 'role') { prev[key] = others[key]; @@ -135,6 +135,8 @@ export default { ...globalProps, onChange: this.handleChange, onClick: this.onClick, + onFocus, + onBlur, }; return ( diff --git a/examples/App.vue b/examples/App.vue index 37487ed53..dff183fcb 100644 --- a/examples/App.vue +++ b/examples/App.vue @@ -4,7 +4,7 @@