mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-28 05:05:48 +08:00
add warning when use getCheckboxProps (#15231)
This commit is contained in:
parent
074363b514
commit
3fbeff3fcc
@ -153,7 +153,12 @@ export default class Table<T> extends React.Component<TableProps<T>, TableState<
|
||||
const key = this.getRecordKey(item, index);
|
||||
// Cache checkboxProps
|
||||
if (!this.CheckboxPropsCache[key]) {
|
||||
this.CheckboxPropsCache[key] = rowSelection.getCheckboxProps(item);
|
||||
const checkboxProps = (this.CheckboxPropsCache[key] = rowSelection.getCheckboxProps(item));
|
||||
warning(
|
||||
!('checked' in checkboxProps) && !('defaultChecked' in checkboxProps),
|
||||
'Table',
|
||||
'Do not set `checked` or `defaultChecked` in `getCheckboxProps`. Please use `selectedRowKeys` instead.',
|
||||
);
|
||||
}
|
||||
return this.CheckboxPropsCache[key];
|
||||
};
|
||||
|
@ -4,6 +4,16 @@ import Table from '..';
|
||||
import Checkbox from '../../checkbox';
|
||||
|
||||
describe('Table.rowSelection', () => {
|
||||
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||
|
||||
afterEach(() => {
|
||||
errorSpy.mockReset();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
errorSpy.mockRestore();
|
||||
});
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: 'Name',
|
||||
@ -120,6 +130,10 @@ describe('Table.rowSelection', () => {
|
||||
checkboxs = wrapper.find('input');
|
||||
expect(checkboxs.at(1).props().checked).toBe(true);
|
||||
expect(checkboxs.at(2).props().checked).toBe(true);
|
||||
|
||||
expect(errorSpy).toBeCalledWith(
|
||||
'Warning: [antd: Table] Do not set `checked` or `defaultChecked` in `getCheckboxProps`. Please use `selectedRowKeys` instead.',
|
||||
);
|
||||
});
|
||||
|
||||
it('can be controlled', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user