mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-18 22:36:31 +08:00
Fix rowSelection defauleChecked
This commit is contained in:
parent
3802f08191
commit
d2918d2456
@ -37,9 +37,7 @@ export default class SelectionBox extends React.Component<SelectionBoxProps, any
|
||||
const { store } = this.props;
|
||||
this.unsubscribe = store.subscribe(() => {
|
||||
const checked = this.getCheckState(this.props);
|
||||
if (checked !== this.state.checked) {
|
||||
this.setState({ checked });
|
||||
}
|
||||
this.setState({ checked });
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -134,6 +134,45 @@ describe('Table', () => {
|
||||
pagers.at(0).simulate('click');
|
||||
expect(checkboxAll.node.state).toEqual({ checked: true, indeterminate: false });
|
||||
});
|
||||
|
||||
// https://github.com/ant-design/ant-design/issues/4020
|
||||
it('handles defaultChecked', () => {
|
||||
const columns = [{
|
||||
title: 'Name',
|
||||
dataIndex: 'name',
|
||||
}];
|
||||
|
||||
const data = [{
|
||||
key: 0,
|
||||
name: 'Jack',
|
||||
}, {
|
||||
key: 1,
|
||||
name: 'Lucy',
|
||||
}];
|
||||
|
||||
const rowSelection = {
|
||||
getCheckboxProps: record => ({
|
||||
defaultChecked: record.key === 0
|
||||
}),
|
||||
}
|
||||
|
||||
const wrapper = mount(
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={data}
|
||||
rowSelection={rowSelection}
|
||||
/>
|
||||
);
|
||||
const checkboxs = wrapper.find('input');
|
||||
|
||||
expect(checkboxs.at(1).props().checked).toBe(true);
|
||||
expect(checkboxs.at(2).props().checked).toBe(false);
|
||||
|
||||
checkboxs.at(2).simulate('change', { target: { checked: true } });
|
||||
|
||||
expect(checkboxs.at(1).props().checked).toBe(true);
|
||||
expect(checkboxs.at(2).props().checked).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('JSX style API', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user