mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-07 09:26:06 +08:00
parent
c2d94ad84d
commit
17b158c091
@ -68,12 +68,16 @@ export default class SelectionCheckboxAll<T> extends
|
||||
setCheckState(props: SelectionCheckboxAllProps<T>) {
|
||||
const checked = this.getCheckState(props);
|
||||
const indeterminate = this.getIndeterminateState(props);
|
||||
if (checked !== this.state.checked) {
|
||||
this.setState({ checked });
|
||||
}
|
||||
if (indeterminate !== this.state.indeterminate) {
|
||||
this.setState({ indeterminate });
|
||||
}
|
||||
this.setState((prevState) => {
|
||||
let newState: SelectionCheckboxAllState = {};
|
||||
if (indeterminate !== prevState.indeterminate) {
|
||||
newState.indeterminate = indeterminate;
|
||||
}
|
||||
if (checked !== prevState.checked) {
|
||||
newState.checked = checked;
|
||||
}
|
||||
return newState;
|
||||
});
|
||||
}
|
||||
|
||||
getCheckState(props: SelectionCheckboxAllProps<T>) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
import React from 'react';
|
||||
import { mount, render } from 'enzyme';
|
||||
import Table from '..';
|
||||
import Checkbox from '../../checkbox';
|
||||
|
||||
describe('Table.rowSelection', () => {
|
||||
const columns = [{
|
||||
@ -359,4 +360,33 @@ describe('Table.rowSelection', () => {
|
||||
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
});
|
||||
|
||||
// https://github.com/ant-design/ant-design/issues/10629
|
||||
it('should keep all checked state when remove item from dataSource', () => {
|
||||
const wrapper = mount(
|
||||
<Table
|
||||
rowSelection={{
|
||||
selectedRowKeys: [0, 1, 2, 3],
|
||||
}}
|
||||
columns={columns}
|
||||
dataSource={data}
|
||||
/>
|
||||
);
|
||||
expect(wrapper.find(Checkbox).length).toBe(5);
|
||||
wrapper.find(Checkbox).forEach((checkbox) => {
|
||||
expect(checkbox.props().checked).toBe(true);
|
||||
expect(checkbox.props().indeterminate).toBe(false);
|
||||
});
|
||||
wrapper.setProps({
|
||||
dataSource: data.slice(1),
|
||||
rowSelection: {
|
||||
selectedRowKeys: [1, 2, 3],
|
||||
},
|
||||
});
|
||||
expect(wrapper.find(Checkbox).length).toBe(4);
|
||||
wrapper.find(Checkbox).forEach((checkbox) => {
|
||||
expect(checkbox.props().checked).toBe(true);
|
||||
expect(checkbox.props().indeterminate).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -162,8 +162,8 @@ export interface SelectionCheckboxAllProps<T> {
|
||||
}
|
||||
|
||||
export interface SelectionCheckboxAllState {
|
||||
checked: boolean;
|
||||
indeterminate: boolean;
|
||||
checked?: boolean;
|
||||
indeterminate?: boolean;
|
||||
}
|
||||
|
||||
export interface SelectionBoxProps {
|
||||
|
Loading…
Reference in New Issue
Block a user