Fix rowSelection defauleChecked

This commit is contained in:
Wei Zhu 2016-11-28 13:35:05 +08:00 committed by 偏右
parent 3802f08191
commit d2918d2456
2 changed files with 40 additions and 3 deletions

View File

@ -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 });
});
}

View File

@ -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', () => {