From 380331df80a878e33eefe9141fb06c3632562bec Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Fri, 30 Nov 2018 22:58:46 +0800 Subject: [PATCH] feat: update checkbox divider dropdown --- components/checkbox/Checkbox.jsx | 5 ++++- components/checkbox/Group.jsx | 3 ++- components/checkbox/__tests__/group.test.js | 17 +++++++++++++++++ components/checkbox/demo/index.vue | 1 + components/checkbox/index.en-US.md | 2 +- components/checkbox/index.zh-CN.md | 3 +-- components/divider/demo/index.vue | 1 + components/dropdown/demo/index.vue | 1 + 8 files changed, 28 insertions(+), 5 deletions(-) diff --git a/components/checkbox/Checkbox.jsx b/components/checkbox/Checkbox.jsx index 763d3c32b..29d4c39ff 100644 --- a/components/checkbox/Checkbox.jsx +++ b/components/checkbox/Checkbox.jsx @@ -55,7 +55,10 @@ export default { } = props const checkboxProps = { props: { ...restProps, prefixCls }, on: restListeners, attrs: getAttrs(this) } if (checkboxGroup) { - checkboxProps.on.change = () => checkboxGroup.toggleOption({ label: children, value: props.value }) + checkboxProps.on.change = (...args) => { + this.$emit('change', ...args) + checkboxGroup.toggleOption({ label: children, value: props.value }) + } checkboxProps.props.checked = checkboxGroup.sValue.indexOf(props.value) !== -1 checkboxProps.props.disabled = props.disabled || checkboxGroup.disabled } else { diff --git a/components/checkbox/Group.jsx b/components/checkbox/Group.jsx index 2ddc14655..4e2e8c989 100644 --- a/components/checkbox/Group.jsx +++ b/components/checkbox/Group.jsx @@ -1,6 +1,7 @@ import Checkbox from './Checkbox' import hasProp from '../_util/props-util' +function noop () {} export default { name: 'ACheckboxGroup', props: { @@ -82,7 +83,7 @@ export default { disabled={'disabled' in option ? option.disabled : props.disabled} value={option.value} checked={state.sValue.indexOf(option.value) !== -1} - onChange={() => this.toggleOption(option)} + onChange={option.onChange || noop} class={`${groupPrefixCls}-item`} > {option.label} diff --git a/components/checkbox/__tests__/group.test.js b/components/checkbox/__tests__/group.test.js index 1fd53a51f..d4db61bde 100644 --- a/components/checkbox/__tests__/group.test.js +++ b/components/checkbox/__tests__/group.test.js @@ -103,4 +103,21 @@ describe('CheckboxGroup', () => { expect(wrapper.vm.sValue).toEqual(['Apple']) }) }) + + // https://github.com/ant-design/ant-design/issues/12642 + it('should trigger onChange in sub Checkbox', () => { + const onChange = jest.fn() + const wrapper = mount({ + render () { + return ( + + + + ) + }, + }) + wrapper.findAll('.ant-checkbox-input').at(0).trigger('change') + expect(onChange).toBeCalled() + expect(onChange.mock.calls[0][0].target.value).toEqual('my') + }) }) diff --git a/components/checkbox/demo/index.vue b/components/checkbox/demo/index.vue index ca86cf930..8fd01a22f 100644 --- a/components/checkbox/demo/index.vue +++ b/components/checkbox/demo/index.vue @@ -29,6 +29,7 @@ category: 'Components', subtitle: '多选框', type: 'Data Entry', + zhType: '数据录入', title: 'Checkbox', render () { return ( diff --git a/components/checkbox/index.en-US.md b/components/checkbox/index.en-US.md index 592ea8f00..5471f0b9a 100644 --- a/components/checkbox/index.en-US.md +++ b/components/checkbox/index.en-US.md @@ -23,7 +23,7 @@ | -------- | ----------- | ---- | ------- | | defaultValue | Default selected value | string\[] | \[] | | disabled | Disable all checkboxes | boolean | false | -| options | Specifies options | string\[] \| Array<{ label: string value: string disabled?: boolean }> | \[] | +| options | Specifies options | string\[] \| Array<{ label: string value: string disabled?: boolean, onChange?: function }> | \[] | | value | Used for setting the currently selected value. | string\[] | \[] | #### events diff --git a/components/checkbox/index.zh-CN.md b/components/checkbox/index.zh-CN.md index aba61cbe2..ff59f2d50 100644 --- a/components/checkbox/index.zh-CN.md +++ b/components/checkbox/index.zh-CN.md @@ -25,9 +25,8 @@ | --- | --- | --- | --- | | defaultValue | 默认选中的选项 | string\[] | \[] | | disabled | 整组失效 | boolean | false | -| options | 指定可选项 | string\[] \| Array<{ label: string value: string disabled?: boolean }> | \[] | +| options | 指定可选项 | string\[] \| Array<{ label: string value: string disabled?: boolean, onChange?: function }> | \[] | | value | 指定选中的选项 | string\[] | \[] | -| onChange | 变化时回调函数 | Function(checkedValue) | - | #### 事件 | 事件名称 | 说明 | 回调参数 | diff --git a/components/divider/demo/index.vue b/components/divider/demo/index.vue index 7a0d89995..a4078213b 100644 --- a/components/divider/demo/index.vue +++ b/components/divider/demo/index.vue @@ -23,6 +23,7 @@ const md = { export default { category: 'Components', type: 'Other', + zhType: '其他', title: 'Divider', subtitle: '分割线', render () { diff --git a/components/dropdown/demo/index.vue b/components/dropdown/demo/index.vue index 6b581f941..7a7c62e45 100644 --- a/components/dropdown/demo/index.vue +++ b/components/dropdown/demo/index.vue @@ -27,6 +27,7 @@ export default { category: 'Components', subtitle: '下拉菜单', type: 'Navigation', + zhType: '导航', title: 'Dropdown', render () { return (