mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-11 11:32:52 +08:00
parent
c2d94ad84d
commit
17b158c091
@ -68,12 +68,16 @@ export default class SelectionCheckboxAll<T> extends
|
|||||||
setCheckState(props: SelectionCheckboxAllProps<T>) {
|
setCheckState(props: SelectionCheckboxAllProps<T>) {
|
||||||
const checked = this.getCheckState(props);
|
const checked = this.getCheckState(props);
|
||||||
const indeterminate = this.getIndeterminateState(props);
|
const indeterminate = this.getIndeterminateState(props);
|
||||||
if (checked !== this.state.checked) {
|
this.setState((prevState) => {
|
||||||
this.setState({ checked });
|
let newState: SelectionCheckboxAllState = {};
|
||||||
}
|
if (indeterminate !== prevState.indeterminate) {
|
||||||
if (indeterminate !== this.state.indeterminate) {
|
newState.indeterminate = indeterminate;
|
||||||
this.setState({ indeterminate });
|
}
|
||||||
}
|
if (checked !== prevState.checked) {
|
||||||
|
newState.checked = checked;
|
||||||
|
}
|
||||||
|
return newState;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getCheckState(props: SelectionCheckboxAllProps<T>) {
|
getCheckState(props: SelectionCheckboxAllProps<T>) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { mount, render } from 'enzyme';
|
import { mount, render } from 'enzyme';
|
||||||
import Table from '..';
|
import Table from '..';
|
||||||
|
import Checkbox from '../../checkbox';
|
||||||
|
|
||||||
describe('Table.rowSelection', () => {
|
describe('Table.rowSelection', () => {
|
||||||
const columns = [{
|
const columns = [{
|
||||||
@ -359,4 +360,33 @@ describe('Table.rowSelection', () => {
|
|||||||
|
|
||||||
expect(wrapper).toMatchSnapshot();
|
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 {
|
export interface SelectionCheckboxAllState {
|
||||||
checked: boolean;
|
checked?: boolean;
|
||||||
indeterminate: boolean;
|
indeterminate?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SelectionBoxProps {
|
export interface SelectionBoxProps {
|
||||||
|
Loading…
Reference in New Issue
Block a user