mirror of
https://github.com/ant-design/ant-design.git
synced 2025-08-06 16:06:28 +08:00
Add name attribute support to Checkbox.Group (#15760)
* Update Checkbox documentation
This commit is contained in:
parent
0fd0faa8a7
commit
a49caabe00
@ -100,6 +100,7 @@ export default class Checkbox extends React.Component<CheckboxProps, {}> {
|
||||
}
|
||||
checkboxGroup.toggleOption({ label: children, value: props.value });
|
||||
};
|
||||
checkboxProps.name = checkboxGroup.name;
|
||||
checkboxProps.checked = checkboxGroup.value.indexOf(props.value) !== -1;
|
||||
checkboxProps.disabled = props.disabled || checkboxGroup.disabled;
|
||||
}
|
||||
|
@ -81,6 +81,7 @@ class CheckboxGroup extends React.Component<CheckboxGroupProps, CheckboxGroupSta
|
||||
toggleOption: this.toggleOption,
|
||||
value: this.state.value,
|
||||
disabled: this.props.disabled,
|
||||
name: this.props.name,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
@ -71,6 +71,16 @@ describe('CheckboxGroup', () => {
|
||||
expect(onChangeGroup).toBeCalledWith(['Apple']);
|
||||
});
|
||||
|
||||
it('all children should have a name property', () => {
|
||||
const wrapper = mount(<Checkbox.Group name="checkboxgroup" options={['Yes', 'No']} />);
|
||||
|
||||
expect(
|
||||
wrapper.find('input[type="checkbox"]').forEach(el => {
|
||||
expect(el.props().name).toEqual('checkboxgroup');
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('passes prefixCls down to checkbox', () => {
|
||||
const options = [{ label: 'Apple', value: 'Apple' }, { label: 'Orange', value: 'Orange' }];
|
||||
|
||||
|
@ -32,6 +32,7 @@ Checkbox component.
|
||||
| -------- | ----------- | ---- | ------- |
|
||||
| defaultValue | Default selected value | string\[] | \[] |
|
||||
| disabled | Disable all checkboxes | boolean | false |
|
||||
| name | The `name` property of all `input[type="checkbox"]` children | string | - |
|
||||
| options | Specifies options | string\[] | \[] |
|
||||
| value | Used for setting the currently selected value. | string\[] | \[] |
|
||||
| onChange | The callback function that is triggered when the state changes. | Function(checkedValue) | - |
|
||||
|
@ -33,6 +33,7 @@ title: Checkbox
|
||||
| --- | --- | --- | --- |
|
||||
| defaultValue | 默认选中的选项 | string\[] | \[] |
|
||||
| disabled | 整组失效 | boolean | false |
|
||||
| name | CheckboxGroup 下所有 `input[type="checkbox"]` 的 `name` 属性 | string | - |
|
||||
| options | 指定可选项 | string\[] | \[] |
|
||||
| value | 指定选中的选项 | string\[] | \[] |
|
||||
| onChange | 变化时回调函数 | Function(checkedValue) | - |
|
||||
|
Loading…
Reference in New Issue
Block a user