Browse Source
fix: Table selection `childrenColumnName` not work (#23205)
* fix childrenPropName
* test case
* update test case
pull/23240/head
二货机器人
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
21 additions and
1 deletions
-
components/table/Table.tsx
-
components/table/__tests__/Table.rowSelection.test.js
|
|
@ -98,6 +98,7 @@ function Table<RecordType extends object = any>(props: TableProps<RecordType>) { |
|
|
|
rowClassName, |
|
|
|
columns, |
|
|
|
children, |
|
|
|
childrenColumnName: legacyChildrenColumnName, |
|
|
|
onChange, |
|
|
|
getPopupContainer, |
|
|
|
loading, |
|
|
@ -106,7 +107,6 @@ function Table<RecordType extends object = any>(props: TableProps<RecordType>) { |
|
|
|
expandedRowRender, |
|
|
|
expandIconColumnIndex, |
|
|
|
indentSize, |
|
|
|
childrenColumnName = 'children', |
|
|
|
scroll, |
|
|
|
sortDirections, |
|
|
|
locale, |
|
|
@ -128,9 +128,11 @@ function Table<RecordType extends object = any>(props: TableProps<RecordType>) { |
|
|
|
const dropdownPrefixCls = getPrefixCls('dropdown', customizeDropdownPrefixCls); |
|
|
|
|
|
|
|
const mergedExpandable: ExpandableConfig<RecordType> = { |
|
|
|
childrenColumnName: legacyChildrenColumnName, |
|
|
|
expandIconColumnIndex, |
|
|
|
...expandable, |
|
|
|
}; |
|
|
|
const { childrenColumnName = 'children' } = mergedExpandable; |
|
|
|
|
|
|
|
const expandType: ExpandType = React.useMemo<ExpandType>(() => { |
|
|
|
if (rawData.some(item => (item as any)[childrenColumnName])) { |
|
|
|
|
|
@ -779,4 +779,22 @@ describe('Table.rowSelection', () => { |
|
|
|
jest.runAllTimers(); |
|
|
|
expect(wrapper.render()).toMatchSnapshot(); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Table selection should check', () => { |
|
|
|
const onChange = jest.fn(); |
|
|
|
const wrapper = mount( |
|
|
|
<Table |
|
|
|
dataSource={[{ name: 'light', sub: [{ name: 'bamboo' }] }]} |
|
|
|
expandable={{ expandedRowKeys: ['light'], childrenColumnName: 'sub' }} |
|
|
|
rowSelection={{ onChange }} |
|
|
|
rowKey="name" |
|
|
|
/>, |
|
|
|
); |
|
|
|
|
|
|
|
wrapper |
|
|
|
.find('input') |
|
|
|
.last() |
|
|
|
.simulate('change', { target: { checked: true } }); |
|
|
|
expect(onChange.mock.calls[0][1]).toEqual([expect.objectContaining({ name: 'bamboo' })]); |
|
|
|
}); |
|
|
|
}); |
|
|
|