diff --git a/components/transfer/__tests__/index.test.js b/components/transfer/__tests__/index.test.js index 171a9d9059..066a9f9c14 100644 --- a/components/transfer/__tests__/index.test.js +++ b/components/transfer/__tests__/index.test.js @@ -212,4 +212,21 @@ describe('Transfer', () => { wrapper.find(TransferOperation).find(Button).at(1).simulate('click'); expect(handleChange).toHaveBeenCalledWith(['1', '3', '4'], 'right', ['1']); }); + + it('should check correctly when there is a search text', () => { + const props = { ...listCommonProps }; + delete props.targetKeys; + delete props.selectedKeys; + const handleSelectChange = jest.fn(); + const wrapper = mount( + item.title} /> + ); + wrapper.find(TransferItem).filterWhere(n => n.prop('item').key === 'b').simulate('click'); + expect(handleSelectChange).toHaveBeenLastCalledWith(['b'], []); + wrapper.find(TransferSearch).at(0).find('input').simulate('change', { target: { value: 'a' } }); + wrapper.find(TransferList).at(0).find('.ant-transfer-list-header input[type="checkbox"]').simulate('change'); + expect(handleSelectChange).toHaveBeenLastCalledWith(['b', 'a'], []); + wrapper.find(TransferList).at(0).find('.ant-transfer-list-header input[type="checkbox"]').simulate('change'); + expect(handleSelectChange).toHaveBeenLastCalledWith(['b'], []); + }); }); diff --git a/components/transfer/index.tsx b/components/transfer/index.tsx index 0b3cdc9688..59d98c58fa 100644 --- a/components/transfer/index.tsx +++ b/components/transfer/index.tsx @@ -187,7 +187,17 @@ abstract class Transfer extends React.Component { } handleSelectAll = (direction, filteredDataSource, checkAll) => { - const holder = checkAll ? [] : filteredDataSource.map(item => item.key); + const originalSelectedKeys = this.state[this.getSelectedKeysName(direction)] || []; + const currentKeys = filteredDataSource.map(item => item.key); + // Only operate current keys from original selected keys + const newKeys1 = originalSelectedKeys.filter(key => currentKeys.indexOf(key) === -1); + const newKeys2 = [...originalSelectedKeys]; + currentKeys.forEach((key) => { + if (newKeys2.indexOf(key) === -1) { + newKeys2.push(key); + } + }); + const holder = checkAll ? newKeys1 : newKeys2; this.handleSelectChange(direction, holder); if (!this.props.selectedKeys) {