Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Table filterDropdown confirm closeDropdown #30457

Merged
merged 3 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 43 additions & 0 deletions components/table/__tests__/Table.filter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,7 @@ describe('Table.filter', () => {

expect(wrapper.find('.ant-table-filter-column')).toHaveLength(3);
});

it('should pagination.current be 1 after filtering', () => {
const onChange = jest.fn();
const columns = [
Expand Down Expand Up @@ -1562,4 +1563,46 @@ describe('Table.filter', () => {
wrapper.find('.ant-btn-primary').first().simulate('click');
expect(onChange.mock.calls[1][0].current).toBe(1);
});

// https://github.com/ant-design/ant-design/issues/30454
it('should not trigger onFilterDropdownVisibleChange when call confirm({ closeDropdown: false })', () => {
const onFilterDropdownVisibleChange = jest.fn();
const wrapper = mount(
createTable({
columns: [
{
title: 'Name',
dataIndex: 'name',
key: 'name',
filteredValue: name,
filterDropdown: ({ confirm }) => (
<>
<button id="confirm-and-close" type="button" onClick={() => confirm()}>
confirm
</button>
<button
id="confirm-only"
type="button"
onClick={() => confirm({ closeDropdown: false })}
>
confirm
</button>
</>
),
onFilterDropdownVisibleChange,
},
],
}),
);

wrapper.find('.ant-dropdown-trigger').first().simulate('click');
expect(onFilterDropdownVisibleChange).toHaveBeenCalledTimes(1);

wrapper.find('#confirm-only').simulate('click');
expect(onFilterDropdownVisibleChange).toHaveBeenCalledTimes(1);

wrapper.find('#confirm-and-close').simulate('click');
expect(onFilterDropdownVisibleChange).toHaveBeenCalledTimes(2);
expect(onFilterDropdownVisibleChange).toHaveBeenLastCalledWith(false);
});
});
2 changes: 1 addition & 1 deletion components/table/demo/custom-filter-panel.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class App extends React.Component {
value={selectedKeys[0]}
onChange={e => setSelectedKeys(e.target.value ? [e.target.value] : [])}
onPressEnter={() => this.handleSearch(selectedKeys, confirm, dataIndex)}
style={{ width: 188, marginBottom: 8, display: 'block' }}
style={{ marginBottom: 8, display: 'block' }}
/>
<Space>
<Button
Expand Down
15 changes: 5 additions & 10 deletions components/table/hooks/useFilter/FilterDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@ import Checkbox from '../../../checkbox';
import Radio from '../../../radio';
import Dropdown from '../../../dropdown';
import Empty from '../../../empty';
import {
ColumnType,
ColumnFilterItem,
Key,
TableLocale,
GetPopupContainer,
FilterConfirmProps,
} from '../../interface';
import { ColumnType, ColumnFilterItem, Key, TableLocale, GetPopupContainer } from '../../interface';
import FilterDropdownMenuWrapper from './FilterWrapper';
import { FilterState } from '.';
import useSyncState from '../../../_util/hooks/useSyncState';
Expand Down Expand Up @@ -192,8 +185,10 @@ function FilterDropdown<RecordType>(props: FilterDropdownProps<RecordType>) {
internalTriggerFilter([]);
};

const doFilter = (param: FilterConfirmProps = { closeDropdown: true }) => {
triggerVisible(!param.closeDropdown);
const doFilter = ({ closeDropdown } = { closeDropdown: true }) => {
if (closeDropdown) {
triggerVisible(false);
}
internalTriggerFilter(getFilteredKeysSync());
};

Expand Down