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:
07akioni 2020-06-12 18:05:46 +08:00 committed by GitHub
parent 905ddfc2c7
commit f6c8f81484
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 0 deletions

View File

@ -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);
});
});

View File

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