Skip to content

Commit

Permalink
fix: Tree filter select all behavior
Browse files Browse the repository at this point in the history
ref #34280
  • Loading branch information
afc163 committed Mar 4, 2022
1 parent 03d8556 commit cb5e7a6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
28 changes: 28 additions & 0 deletions components/table/__tests__/Table.filter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand Down
5 changes: 5 additions & 0 deletions components/table/hooks/useFilter/FilterDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,11 @@ function FilterDropdown<RecordType>(props: FilterDropdownProps<RecordType>) {
<div className={`${tablePrefixCls}-filter-dropdown-tree`}>
{filterMultiple ? (
<Checkbox
checked={selectedKeys.length === flattenKeys(column.filters).length}
indeterminate={
selectedKeys.length > 0 &&
selectedKeys.length < flattenKeys(column.filters).length
}
className={`${tablePrefixCls}-filter-dropdown-checkall`}
onChange={onCheckAll}
>
Expand Down

0 comments on commit cb5e7a6

Please sign in to comment.