mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-18 22:36:31 +08:00
fix: shoundn't keep table filterDropdown inner status in controlled mode (#24952)
* fix: shoundn't keep table filterDropdown inner status in controlled mode * chore: remove useless code in table.filter.test
This commit is contained in:
parent
905ddfc2c7
commit
f6c8f81484
@ -1148,4 +1148,32 @@ describe('Table.filter', () => {
|
||||
expect(wrapper.find('tbody tr')).toHaveLength(1);
|
||||
expect(wrapper.find('tbody tr td').text()).toEqual('Jack');
|
||||
});
|
||||
|
||||
it(`shouldn't keep status when controlled filteredValue isn't change`, () => {
|
||||
const filterControlledColumn = {
|
||||
title: 'Name',
|
||||
dataIndex: 'name',
|
||||
filteredValue: null,
|
||||
filters: [
|
||||
{ text: 'Boy', value: 'boy' },
|
||||
{ text: 'Girl', value: 'girl' },
|
||||
],
|
||||
onFilter: filterFn,
|
||||
};
|
||||
const wrapper = mount(createTable({ columns: [filterControlledColumn] }));
|
||||
wrapper.find('.ant-dropdown-trigger').first().simulate('click');
|
||||
wrapper.find('FilterDropdown').find('MenuItem').first().simulate('click');
|
||||
wrapper // close drodown
|
||||
.find('FilterDropdown')
|
||||
.find('.ant-table-filter-dropdown-btns .ant-btn-primary')
|
||||
.simulate('click');
|
||||
wrapper.find('.ant-dropdown-trigger').first().simulate('click'); // reopen
|
||||
const checkbox = wrapper
|
||||
.find('FilterDropdown')
|
||||
.find('MenuItem')
|
||||
.first()
|
||||
.find('Checkbox')
|
||||
.first();
|
||||
expect(checkbox.props().checked).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
@ -154,6 +154,11 @@ function FilterDropdown<RecordType>(props: FilterDropdownProps<RecordType>) {
|
||||
};
|
||||
|
||||
const onVisibleChange = (newVisible: boolean) => {
|
||||
if (newVisible && propFilteredKeys !== undefined) {
|
||||
// Sync filteredKeys on appear in controlled mode (propFilteredKeys !== undefiend)
|
||||
setFilteredKeysSync(propFilteredKeys || []);
|
||||
}
|
||||
|
||||
triggerVisible(newVisible);
|
||||
|
||||
// Default will filter when closed
|
||||
|
Loading…
Reference in New Issue
Block a user