fix: checkbox focus & blur not work

pull/2682/head
tanjinzhou 2020-07-28 16:04:12 +08:00
parent 42431d39a2
commit 777d1d5dda
4 changed files with 18 additions and 43 deletions

@ -1 +1 @@
Subproject commit 156f6e903435aff90e130518d80dd676fae22c5d Subproject commit 46fbd8fd067c497a740594a1b8cc8e503fc94a8a

View File

@ -17,25 +17,13 @@ describe('CheckboxGroup', () => {
sync: false, sync: false,
}, },
); );
wrapper wrapper.findAll('.ant-checkbox-input')[0].trigger('change');
.findAll('.ant-checkbox-input')
.at(0)
.trigger('change');
expect(onChange).toHaveBeenCalledWith(['Apple']); expect(onChange).toHaveBeenCalledWith(['Apple']);
wrapper wrapper.findAll('.ant-checkbox-input')[1].trigger('change');
.findAll('.ant-checkbox-input')
.at(1)
.trigger('change');
expect(onChange).toHaveBeenCalledWith(['Apple', 'Pear']); expect(onChange).toHaveBeenCalledWith(['Apple', 'Pear']);
wrapper wrapper.findAll('.ant-checkbox-input')[2].trigger('change');
.findAll('.ant-checkbox-input')
.at(2)
.trigger('change');
expect(onChange).toHaveBeenCalledWith(['Apple', 'Pear', 'Orange']); expect(onChange).toHaveBeenCalledWith(['Apple', 'Pear', 'Orange']);
wrapper wrapper.findAll('.ant-checkbox-input')[1].trigger('change');
.findAll('.ant-checkbox-input')
.at(1)
.trigger('change');
expect(onChange).toHaveBeenCalledWith(['Apple', 'Orange']); expect(onChange).toHaveBeenCalledWith(['Apple', 'Orange']);
}); });
@ -57,15 +45,9 @@ describe('CheckboxGroup', () => {
sync: false, sync: false,
}, },
); );
groupWrapper groupWrapper.findAll('.ant-checkbox-input')[0].trigger('change');
.findAll('.ant-checkbox-input')
.at(0)
.trigger('change');
expect(onChangeGroup).not.toBeCalled(); expect(onChangeGroup).not.toBeCalled();
groupWrapper groupWrapper.findAll('.ant-checkbox-input')[1].trigger('change');
.findAll('.ant-checkbox-input')
.at(1)
.trigger('change');
expect(onChangeGroup).not.toBeCalled(); expect(onChangeGroup).not.toBeCalled();
}); });
@ -87,15 +69,9 @@ describe('CheckboxGroup', () => {
sync: false, sync: false,
}, },
); );
groupWrapper groupWrapper.findAll('.ant-checkbox-input')[0].trigger('change');
.findAll('.ant-checkbox-input')
.at(0)
.trigger('change');
expect(onChangeGroup).toHaveBeenCalledWith(['Apple']); expect(onChangeGroup).toHaveBeenCalledWith(['Apple']);
groupWrapper groupWrapper.findAll('.ant-checkbox-input')[1].trigger('change');
.findAll('.ant-checkbox-input')
.at(1)
.trigger('change');
expect(onChangeGroup).toHaveBeenCalledWith(['Apple']); expect(onChangeGroup).toHaveBeenCalledWith(['Apple']);
}); });
@ -143,10 +119,7 @@ describe('CheckboxGroup', () => {
); );
}, },
}); });
wrapper wrapper.findAll('.ant-checkbox-input')[0].trigger('change');
.findAll('.ant-checkbox-input')
.at(0)
.trigger('change');
expect(onChange).toBeCalled(); expect(onChange).toBeCalled();
expect(onChange.mock.calls[0][0].target.value).toEqual('my'); expect(onChange.mock.calls[0][0].target.value).toEqual('my');
}); });

View File

@ -45,8 +45,10 @@ export default {
}, },
mounted() { mounted() {
nextTick(() => { nextTick(() => {
if (this.autofocus) { if (process.env.NODE_ENV === 'test') {
this.$refs.input && this.$refs.input.focus(); if (this.autofocus) {
this.$refs.input && this.$refs.input.focus();
}
} }
}); });
}, },
@ -103,12 +105,10 @@ export default {
readonly, readonly,
tabindex, tabindex,
autofocus, autofocus,
onFocus,
onBlur,
value, value,
...others ...others
} = getOptionProps(this); } = getOptionProps(this);
const { class: className } = this.$attrs; const { class: className, onFocus, onBlur } = this.$attrs;
const globalProps = Object.keys({ ...others, ...this.$attrs }).reduce((prev, key) => { const globalProps = Object.keys({ ...others, ...this.$attrs }).reduce((prev, key) => {
if (key.substr(0, 5) === 'aria-' || key.substr(0, 5) === 'data-' || key === 'role') { if (key.substr(0, 5) === 'aria-' || key.substr(0, 5) === 'data-' || key === 'role') {
prev[key] = others[key]; prev[key] = others[key];
@ -135,6 +135,8 @@ export default {
...globalProps, ...globalProps,
onChange: this.handleChange, onChange: this.handleChange,
onClick: this.onClick, onClick: this.onClick,
onFocus,
onBlur,
}; };
return ( return (

View File

@ -4,7 +4,7 @@
</div> </div>
</template> </template>
<script> <script>
import demo from '../antdv-demo/docs/cascader/demo/index'; import demo from '../antdv-demo/docs/checkbox/demo/basic';
export default { export default {
components: { components: {