mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 11:10:01 +08:00
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:
parent
deea6feecf
commit
de7155234a
@ -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);
|
||||
|
@ -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 () => {
|
||||
|
Loading…
Reference in New Issue
Block a user