mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-02 03:59:01 +08:00
fix(ColorPicker): should not trigger onChange when click clear after clearing (#42643)
This commit is contained in:
parent
3244e6491c
commit
0afe8baf1e
@ -24,6 +24,7 @@ const ColorPickerPanel: FC<ColorPickerPanelProps> = (props) => {
|
|||||||
onClear,
|
onClear,
|
||||||
onChangeComplete,
|
onChangeComplete,
|
||||||
color,
|
color,
|
||||||
|
colorCleared,
|
||||||
...injectProps
|
...injectProps
|
||||||
} = props;
|
} = props;
|
||||||
const colorPickerPanelPrefixCls = `${prefixCls}-inner-panel`;
|
const colorPickerPanelPrefixCls = `${prefixCls}-inner-panel`;
|
||||||
@ -34,6 +35,7 @@ const ColorPickerPanel: FC<ColorPickerPanelProps> = (props) => {
|
|||||||
<ColorClear
|
<ColorClear
|
||||||
prefixCls={prefixCls}
|
prefixCls={prefixCls}
|
||||||
value={color}
|
value={color}
|
||||||
|
colorCleared={colorCleared}
|
||||||
onChange={(clearColor) => {
|
onChange={(clearColor) => {
|
||||||
onChange?.(clearColor);
|
onChange?.(clearColor);
|
||||||
onClear?.();
|
onClear?.();
|
||||||
|
@ -277,6 +277,16 @@ describe('ColorPicker', () => {
|
|||||||
).toEqual('background: rgb(99, 22, 22);');
|
).toEqual('background: rgb(99, 22, 22);');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Should not trigger onChange when click clear after clearing', async () => {
|
||||||
|
const onChange = jest.fn();
|
||||||
|
const { container } = render(<ColorPicker allowClear onChange={onChange} />);
|
||||||
|
fireEvent.click(container.querySelector('.ant-color-picker-trigger')!);
|
||||||
|
fireEvent.click(container.querySelector('.ant-color-picker-clear')!);
|
||||||
|
expect(onChange).toHaveBeenCalledTimes(1);
|
||||||
|
fireEvent.click(container.querySelector('.ant-popover .ant-color-picker-clear')!);
|
||||||
|
expect(onChange).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
it('Should fix hover boundary issues', async () => {
|
it('Should fix hover boundary issues', async () => {
|
||||||
spyElementPrototypes(HTMLElement, {
|
spyElementPrototypes(HTMLElement, {
|
||||||
getBoundingClientRect: () => ({
|
getBoundingClientRect: () => ({
|
||||||
|
@ -4,14 +4,14 @@ import type { Color } from '../color';
|
|||||||
import type { ColorPickerBaseProps } from '../interface';
|
import type { ColorPickerBaseProps } from '../interface';
|
||||||
import { generateColor } from '../util';
|
import { generateColor } from '../util';
|
||||||
|
|
||||||
interface ColorClearProps extends Pick<ColorPickerBaseProps, 'prefixCls'> {
|
interface ColorClearProps extends Pick<ColorPickerBaseProps, 'prefixCls' | 'colorCleared'> {
|
||||||
value?: Color;
|
value?: Color;
|
||||||
onChange?: (value: Color) => void;
|
onChange?: (value: Color) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ColorClear: FC<ColorClearProps> = ({ prefixCls, value, onChange }) => {
|
const ColorClear: FC<ColorClearProps> = ({ prefixCls, value, colorCleared, onChange }) => {
|
||||||
const handleClick = () => {
|
const handleClick = () => {
|
||||||
if (value) {
|
if (value && !colorCleared) {
|
||||||
const hsba = value.toHsb();
|
const hsba = value.toHsb();
|
||||||
hsba.a = 0;
|
hsba.a = 0;
|
||||||
const genColor = generateColor(hsba);
|
const genColor = generateColor(hsba);
|
||||||
|
Loading…
Reference in New Issue
Block a user