fix: table onChange event is fired every time when close filterDropdown

Close #11164
This commit is contained in:
Andrzej Dybionka 2018-07-04 14:24:44 +02:00 committed by Wei Zhu
parent e91f67b87c
commit 968371b22a
2 changed files with 14 additions and 2 deletions

View File

@ -223,6 +223,16 @@ describe('Table.filter', () => {
expect(handleChange).toBeCalledWith({}, { name: ['boy'] }, {});
});
it('should not fire change event on close filterDropdown without changing anything', () => {
const handleChange = jest.fn();
const wrapper = mount(createTable({ onChange: handleChange }));
const dropdownWrapper = mount(wrapper.find('Trigger').instance().getComponent());
dropdownWrapper.find('.clear').simulate('click');
expect(handleChange).not.toHaveBeenCalled();
});
it('three levels menu', () => {
const filters = [
{ text: 'Upper', value: 'Upper' },

View File

@ -108,8 +108,10 @@ export default class FilterMenu<T> extends React.Component<FilterMenuProps<T>, F
}
confirmFilter() {
if (this.state.selectedKeys !== this.props.selectedKeys) {
this.props.confirmFilter(this.props.column, this.state.selectedKeys);
const { selectedKeys } = this.state;
if (!shallowequal(selectedKeys, this.props.selectedKeys)) {
this.props.confirmFilter(this.props.column, selectedKeys);
}
}