fix: ColorPicker onChangeComplete not called when change value (#43867)

* fix: color-picker onChangeComplete not called when change value

* refactor: optimized code
This commit is contained in:
红果汁 2023-07-28 14:36:46 +08:00 committed by GitHub
parent deea6feecf
commit de7155234a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -168,9 +168,12 @@ const ColorPicker: CompoundedComponent = (props) => {
if (disabledAlpha && isAlphaColor) {
color = genAlphaColor(color);
}
// Only for drag-and-drop color picking
if (pickColor) {
popupAllowCloseRef.current = false;
} else {
onChangeComplete?.(color);
}
setColorValue(color);

View File

@ -459,9 +459,16 @@ describe('ColorPicker', () => {
it('Should onChangeComplete work', async () => {
const handleChangeComplete = jest.fn();
const { container } = render(<ColorPicker open onChangeComplete={handleChangeComplete} />);
const { container } = render(
<ColorPicker open onChangeComplete={handleChangeComplete} allowClear />,
);
doMouseMove(container, 0, 999);
expect(handleChangeComplete).toHaveBeenCalledTimes(1);
fireEvent.click(container.querySelector('.ant-color-picker-clear')!);
fireEvent.change(container.querySelector('.ant-color-picker-hex-input input')!, {
target: { value: '#273B57' },
});
expect(handleChangeComplete).toHaveBeenCalledTimes(3);
});
it('Should disabledAlpha work', async () => {