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, |
|
|
rowClassName, |
|
|
columns, |
|
|
columns, |
|
|
children, |
|
|
children, |
|
|
|
|
|
childrenColumnName: legacyChildrenColumnName, |
|
|
onChange, |
|
|
onChange, |
|
|
getPopupContainer, |
|
|
getPopupContainer, |
|
|
loading, |
|
|
loading, |
|
@ -106,7 +107,6 @@ function Table<RecordType extends object = any>(props: TableProps<RecordType>) { |
|
|
expandedRowRender, |
|
|
expandedRowRender, |
|
|
expandIconColumnIndex, |
|
|
expandIconColumnIndex, |
|
|
indentSize, |
|
|
indentSize, |
|
|
childrenColumnName = 'children', |
|
|
|
|
|
scroll, |
|
|
scroll, |
|
|
sortDirections, |
|
|
sortDirections, |
|
|
locale, |
|
|
locale, |
|
@ -128,9 +128,11 @@ function Table<RecordType extends object = any>(props: TableProps<RecordType>) { |
|
|
const dropdownPrefixCls = getPrefixCls('dropdown', customizeDropdownPrefixCls); |
|
|
const dropdownPrefixCls = getPrefixCls('dropdown', customizeDropdownPrefixCls); |
|
|
|
|
|
|
|
|
const mergedExpandable: ExpandableConfig<RecordType> = { |
|
|
const mergedExpandable: ExpandableConfig<RecordType> = { |
|
|
|
|
|
childrenColumnName: legacyChildrenColumnName, |
|
|
expandIconColumnIndex, |
|
|
expandIconColumnIndex, |
|
|
...expandable, |
|
|
...expandable, |
|
|
}; |
|
|
}; |
|
|
|
|
|
const { childrenColumnName = 'children' } = mergedExpandable; |
|
|
|
|
|
|
|
|
const expandType: ExpandType = React.useMemo<ExpandType>(() => { |
|
|
const expandType: ExpandType = React.useMemo<ExpandType>(() => { |
|
|
if (rawData.some(item => (item as any)[childrenColumnName])) { |
|
|
if (rawData.some(item => (item as any)[childrenColumnName])) { |
|
|
|
@ -779,4 +779,22 @@ describe('Table.rowSelection', () => { |
|
|
jest.runAllTimers(); |
|
|
jest.runAllTimers(); |
|
|
expect(wrapper.render()).toMatchSnapshot(); |
|
|
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' })]); |
|
|
|
|
|
}); |
|
|
}); |
|
|
}); |
|
|