fix: Table childColumnName should support checkStrictly (#28568)

This commit is contained in:
二货机器人 2020-12-28 15:18:04 +08:00 committed by GitHub
parent 6c63a742aa
commit 076f5f1f00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 3 deletions

View File

@ -1057,6 +1057,37 @@ describe('Table.rowSelection', () => {
expect(getIndeterminateSelection(wrapper)).toEqual([]); expect(getIndeterminateSelection(wrapper)).toEqual([]);
expect(onChange.mock.calls[2][0]).toEqual(['Jerry Tom Tom']); expect(onChange.mock.calls[2][0]).toEqual(['Jerry Tom Tom']);
}); });
it('should support `childrenColumnName`', () => {
const onChange = jest.fn();
const table = createTable({
dataSource: [
{
key: 0,
name: 'Jack',
childList: [
{ key: 1, name: 'Light' },
{ key: 2, name: 'Bamboo' },
],
},
],
expandable: {
childrenColumnName: 'childList',
defaultExpandAllRows: true,
},
rowSelection: {
checkStrictly: false,
onChange,
},
});
const wrapper = mount(table);
const checkboxes = wrapper.find('input');
expect(checkboxes).toHaveLength(1 + 3);
checkboxes.at(1).simulate('change', { target: { checked: true } });
expect(getSelections(wrapper)).toEqual([0, 1, 2]);
});
}); });
it('warns when set `indeterminate` using `rowSelection.getCheckboxProps` is not allowed with tree structured data.', () => { it('warns when set `indeterminate` using `rowSelection.getCheckboxProps` is not allowed with tree structured data.', () => {
resetWarned(); resetWarned();

View File

@ -117,8 +117,11 @@ export default function useSelection<RecordType>(
() => () =>
checkStrictly checkStrictly
? { keyEntities: null } ? { keyEntities: null }
: convertDataToEntities((data as unknown) as DataNode[], undefined, getRowKey as any), : convertDataToEntities((data as unknown) as DataNode[], {
[data, getRowKey, checkStrictly], externalGetKey: getRowKey as any,
childrenPropName: childrenColumnName,
}),
[data, getRowKey, checkStrictly, childrenColumnName],
); );
// Get flatten data // Get flatten data

View File

@ -143,7 +143,7 @@
"rc-tabs": "~11.7.0", "rc-tabs": "~11.7.0",
"rc-textarea": "~0.3.0", "rc-textarea": "~0.3.0",
"rc-tooltip": "~5.0.0", "rc-tooltip": "~5.0.0",
"rc-tree": "~4.0.0", "rc-tree": "~4.1.0",
"rc-tree-select": "~4.2.0", "rc-tree-select": "~4.2.0",
"rc-upload": "~3.3.4", "rc-upload": "~3.3.4",
"rc-util": "^5.1.0", "rc-util": "^5.1.0",