fix(Table): filterSearch function does not execute when filterMode is tree (#37587)

This commit is contained in:
edc-hui 2022-09-17 14:22:26 +08:00 committed by GitHub
parent 646b71b418
commit ff6fd118de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 1 deletions

View File

@ -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(

View File

@ -369,7 +369,12 @@ function FilterDropdown<RecordType>(props: FilterDropdownProps<RecordType>) {
defaultExpandAll
filterTreeNode={
searchValue.trim()
? node => searchValueMatched(searchValue, node.title)
? node => {
if (typeof filterSearch === 'function') {
return filterSearch(searchValue, node);
}
return searchValueMatched(searchValue, node.title);
}
: undefined
}
/>