mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-03 04:30:06 +08:00
Fix Transfer selection when searching text, close #5993
This commit is contained in:
parent
f5d371f6e9
commit
c8d9e64809
@ -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(
|
||||
<Transfer {...props} showSearch onSelectChange={handleSelectChange} render={item => 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'], []);
|
||||
});
|
||||
});
|
||||
|
@ -187,7 +187,17 @@ abstract class Transfer extends React.Component<TransferProps, any> {
|
||||
}
|
||||
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user