Browse Source

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

Close #11164
pull/11438/head
Andrzej Dybionka 6 years ago
committed by Wei Zhu
parent
commit
968371b22a
  1. 10
      components/table/__tests__/Table.filter.test.js
  2. 6
      components/table/filterDropdown.tsx

10
components/table/__tests__/Table.filter.test.js

@ -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' },

6
components/table/filterDropdown.tsx

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

Loading…
Cancel
Save