From ff6fd118de164abac0ae1041292f714fb32581ca Mon Sep 17 00:00:00 2001 From: edc-hui Date: Sat, 17 Sep 2022 14:22:26 +0800 Subject: [PATCH] fix(Table): filterSearch function does not execute when filterMode is tree (#37587) --- .../table/__tests__/Table.filter.test.tsx | 28 +++++++++++++++++++ .../table/hooks/useFilter/FilterDropdown.tsx | 7 ++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/components/table/__tests__/Table.filter.test.tsx b/components/table/__tests__/Table.filter.test.tsx index 314610f83a..271b84ba75 100644 --- a/components/table/__tests__/Table.filter.test.tsx +++ b/components/table/__tests__/Table.filter.test.tsx @@ -1940,6 +1940,34 @@ describe('Table.filter', () => { expect(container.querySelectorAll('li.ant-dropdown-menu-item').length).toBe(2); }); + it('should supports filterSearch has type of function when filterMode is tree', () => { + jest.spyOn(console, 'error').mockImplementation(() => undefined); + const { container } = render( + createTable({ + columns: [ + { + ...column, + filterMode: 'tree', + filters: [ + { text: '节点一', value: 'node1' }, + { text: '节点二', value: 'node2' }, + { text: '节点三', value: 'node3' }, + ], + filterSearch: (input: any, record: any) => record.title.includes(input), + }, + ], + }), + ); + fireEvent.click(container.querySelector('span.ant-dropdown-trigger')!, nativeEvent); + act(() => { + jest.runAllTimers(); + }); + expect(container.querySelectorAll('.ant-table-filter-dropdown-tree').length).toBe(1); + expect(container.querySelectorAll('.ant-input').length).toBe(1); + fireEvent.change(container.querySelector('.ant-input')!, { target: { value: '节点二' } }); + expect(container.querySelectorAll('.ant-tree-treenode.filter-node').length).toBe(1); + }); + it('supports check all items', () => { jest.spyOn(console, 'error').mockImplementation(() => undefined); const { container } = render( diff --git a/components/table/hooks/useFilter/FilterDropdown.tsx b/components/table/hooks/useFilter/FilterDropdown.tsx index c829013634..1dac838b41 100644 --- a/components/table/hooks/useFilter/FilterDropdown.tsx +++ b/components/table/hooks/useFilter/FilterDropdown.tsx @@ -369,7 +369,12 @@ function FilterDropdown(props: FilterDropdownProps) { defaultExpandAll filterTreeNode={ searchValue.trim() - ? node => searchValueMatched(searchValue, node.title) + ? node => { + if (typeof filterSearch === 'function') { + return filterSearch(searchValue, node); + } + return searchValueMatched(searchValue, node.title); + } : undefined } />