fix: Make Select component fire onChange listener when a selection is pasted in (#25993)
This commit is contained in:
parent
210f1f8f95
commit
5fccf67cdc
|
|
@ -868,6 +868,20 @@ test('fires onChange when clearing the selection in multiple mode', async () =>
|
|||
expect(onChange).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test('fires onChange when pasting a selection', async () => {
|
||||
const onChange = jest.fn();
|
||||
render(<AsyncSelect {...defaultProps} onChange={onChange} />);
|
||||
await open();
|
||||
const input = getElementByClassName('.ant-select-selection-search-input');
|
||||
const paste = createEvent.paste(input, {
|
||||
clipboardData: {
|
||||
getData: () => OPTIONS[0].label,
|
||||
},
|
||||
});
|
||||
fireEvent(input, paste);
|
||||
expect(onChange).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test('does not duplicate options when using numeric values', async () => {
|
||||
render(
|
||||
<AsyncSelect
|
||||
|
|
|
|||
|
|
@ -554,6 +554,7 @@ const AsyncSelect = forwardRef(
|
|||
...values,
|
||||
]);
|
||||
}
|
||||
fireOnChange();
|
||||
};
|
||||
|
||||
const shouldRenderChildrenOptions = useMemo(
|
||||
|
|
|
|||
|
|
@ -985,6 +985,20 @@ test('fires onChange when clearing the selection in multiple mode', async () =>
|
|||
expect(onChange).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test('fires onChange when pasting a selection', async () => {
|
||||
const onChange = jest.fn();
|
||||
render(<Select {...defaultProps} onChange={onChange} />);
|
||||
await open();
|
||||
const input = getElementByClassName('.ant-select-selection-search-input');
|
||||
const paste = createEvent.paste(input, {
|
||||
clipboardData: {
|
||||
getData: () => OPTIONS[0].label,
|
||||
},
|
||||
});
|
||||
fireEvent(input, paste);
|
||||
expect(onChange).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test('does not duplicate options when using numeric values', async () => {
|
||||
render(
|
||||
<Select
|
||||
|
|
|
|||
|
|
@ -571,6 +571,7 @@ const Select = forwardRef(
|
|||
]);
|
||||
}
|
||||
}
|
||||
fireOnChange();
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
|
|||
Loading…
Reference in New Issue