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,
|
||||
onChangeComplete,
|
||||
color,
|
||||
colorCleared,
|
||||
...injectProps
|
||||
} = props;
|
||||
const colorPickerPanelPrefixCls = `${prefixCls}-inner-panel`;
|
||||
@ -34,6 +35,7 @@ const ColorPickerPanel: FC<ColorPickerPanelProps> = (props) => {
|
||||
<ColorClear
|
||||
prefixCls={prefixCls}
|
||||
value={color}
|
||||
colorCleared={colorCleared}
|
||||
onChange={(clearColor) => {
|
||||
onChange?.(clearColor);
|
||||
onClear?.();
|
||||
|
@ -277,6 +277,16 @@ describe('ColorPicker', () => {
|
||||
).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 () => {
|
||||
spyElementPrototypes(HTMLElement, {
|
||||
getBoundingClientRect: () => ({
|
||||
|
@ -4,14 +4,14 @@ import type { Color } from '../color';
|
||||
import type { ColorPickerBaseProps } from '../interface';
|
||||
import { generateColor } from '../util';
|
||||
|
||||
interface ColorClearProps extends Pick<ColorPickerBaseProps, 'prefixCls'> {
|
||||
interface ColorClearProps extends Pick<ColorPickerBaseProps, 'prefixCls' | 'colorCleared'> {
|
||||
value?: Color;
|
||||
onChange?: (value: Color) => void;
|
||||
}
|
||||
|
||||
const ColorClear: FC<ColorClearProps> = ({ prefixCls, value, onChange }) => {
|
||||
const ColorClear: FC<ColorClearProps> = ({ prefixCls, value, colorCleared, onChange }) => {
|
||||
const handleClick = () => {
|
||||
if (value) {
|
||||
if (value && !colorCleared) {
|
||||
const hsba = value.toHsb();
|
||||
hsba.a = 0;
|
||||
const genColor = generateColor(hsba);
|
||||
|
Loading…
Reference in New Issue
Block a user