fix additional className (#14770)

This commit is contained in:
zombieJ 2019-02-11 01:00:33 +08:00 committed by GitHub
parent 57f4c62368
commit 67ad35bc26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -208,6 +208,10 @@ export default class Table<T> extends React.Component<TableProps<T>, TableState<
this.store.setState({
selectedRowKeys: nextProps.rowSelection.selectedRowKeys || [],
});
} else if (this.props.rowSelection && !nextProps.rowSelection) {
this.store.setState({
selectedRowKeys: [],
});
}
if ('dataSource' in nextProps && nextProps.dataSource !== this.props.dataSource) {
this.store.setState({

View File

@ -651,4 +651,17 @@ describe('Table.rowSelection', () => {
checkboxes.at(2).simulate('change', { target: { checked: true } });
expect(checkboxAll.instance().state).toEqual({ indeterminate: false, checked: true });
});
it('clear selection className when remove `rowSelection`', () => {
const dataSource = [{ id: 1, name: 'Hello', age: 10 }, { id: 2, name: 'World', age: 30 }];
const wrapper = mount(<Table columns={columns} dataSource={dataSource} rowSelection={{}} />);
const checkboxes = wrapper.find('input');
checkboxes.at(1).simulate('change', { target: { checked: true } });
expect(wrapper.find('.ant-table-row-selected').length).toBe(1);
wrapper.setProps({ rowSelection: null });
expect(wrapper.find('.ant-table-row-selected').length).toBe(0);
});
});