From 1df2ecd66e25a43286ca2da810c7c5e7671429fb Mon Sep 17 00:00:00 2001 From: afc163 Date: Fri, 4 Mar 2022 15:36:18 +0800 Subject: [PATCH] fix: Tree filter select all behavior (#34295) ref https://github.com/ant-design/ant-design/issues/34280 --- .../table/__tests__/Table.filter.test.js | 28 +++++++++++++++++++ .../table/hooks/useFilter/FilterDropdown.tsx | 5 ++++ 2 files changed, 33 insertions(+) diff --git a/components/table/__tests__/Table.filter.test.js b/components/table/__tests__/Table.filter.test.js index 132f8ffc66..2a717b641c 100644 --- a/components/table/__tests__/Table.filter.test.js +++ b/components/table/__tests__/Table.filter.test.js @@ -1964,6 +1964,34 @@ describe('Table.filter', () => { expect(wrapper.find('.ant-tree-checkbox').at(0).hasClass('ant-tree-checkbox-checked')).toBe( true, ); + expect(wrapper.find('.ant-table-filter-dropdown-checkall .ant-checkbox').hasClass('ant-checkbox-indeterminate')).toBe(true); + }); + + it('select-all checkbox should change when all items are selected', () => { + jest.useFakeTimers(); + jest.spyOn(console, 'error').mockImplementation(() => undefined); + const wrapper = mount( + createTable({ + columns: [ + { + ...column, + filterMode: 'tree', + filters: [ + { text: 'Boy', value: 'boy' }, + { text: 'Girl', value: 'girl' }, + ], + }, + ], + }), + ); + wrapper.find('span.ant-dropdown-trigger').simulate('click', nativeEvent); + act(() => { + jest.runAllTimers(); + wrapper.update(); + }); + wrapper.find('.ant-tree-node-content-wrapper').at(0).simulate('click'); + wrapper.find('.ant-tree-node-content-wrapper').at(1).simulate('click'); + expect(wrapper.find('.ant-table-filter-dropdown-checkall .ant-checkbox').hasClass('ant-checkbox-checked')).toBe(true); }); }); diff --git a/components/table/hooks/useFilter/FilterDropdown.tsx b/components/table/hooks/useFilter/FilterDropdown.tsx index ac0b5393d1..4db31f7011 100644 --- a/components/table/hooks/useFilter/FilterDropdown.tsx +++ b/components/table/hooks/useFilter/FilterDropdown.tsx @@ -326,6 +326,11 @@ function FilterDropdown(props: FilterDropdownProps) {
{filterMultiple ? ( 0 && + selectedKeys.length < flattenKeys(column.filters).length + } className={`${tablePrefixCls}-filter-dropdown-checkall`} onChange={onCheckAll} >