From 968371b22a29dbc86f4e3a6009304e1a8c8f5591 Mon Sep 17 00:00:00 2001 From: Andrzej Dybionka Date: Wed, 4 Jul 2018 14:24:44 +0200 Subject: [PATCH] fix: table onChange event is fired every time when close filterDropdown Close #11164 --- components/table/__tests__/Table.filter.test.js | 10 ++++++++++ components/table/filterDropdown.tsx | 6 ++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/components/table/__tests__/Table.filter.test.js b/components/table/__tests__/Table.filter.test.js index 140959585d..3b1a1bfaa4 100644 --- a/components/table/__tests__/Table.filter.test.js +++ b/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' }, diff --git a/components/table/filterDropdown.tsx b/components/table/filterDropdown.tsx index ec0a958820..acbac6b2d7 100755 --- a/components/table/filterDropdown.tsx +++ b/components/table/filterDropdown.tsx @@ -108,8 +108,10 @@ export default class FilterMenu extends React.Component, 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); } }