Skip to content

Commit

Permalink
Fix rowSelection defauleChecked
Browse files Browse the repository at this point in the history
  • Loading branch information
yesmeck authored and afc163 committed Dec 2, 2016
1 parent 3802f08 commit d2918d2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
4 changes: 1 addition & 3 deletions components/table/SelectionBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
});
}

Expand Down
39 changes: 39 additions & 0 deletions tests/table/Table.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit d2918d2

Please sign in to comment.