mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-11-30 02:59:04 +08:00
fix: ColorPicker presets cannot be selected (#42882)
* fix: color-picker presets not checked * test: update test case * fix: color-picker presets not checked * test: update test case
This commit is contained in:
parent
b4b6b5c511
commit
243704330b
@ -196,6 +196,9 @@ describe('ColorPicker', () => {
|
|||||||
expect(
|
expect(
|
||||||
container.querySelector('.ant-color-picker-hex-input input')?.getAttribute('value'),
|
container.querySelector('.ant-color-picker-hex-input input')?.getAttribute('value'),
|
||||||
).toEqual('000000');
|
).toEqual('000000');
|
||||||
|
expect(container.querySelectorAll('.ant-color-picker-presets-color')[0]).toHaveClass(
|
||||||
|
'ant-color-picker-presets-color-checked',
|
||||||
|
);
|
||||||
|
|
||||||
fireEvent.click(presetsColors[9]);
|
fireEvent.click(presetsColors[9]);
|
||||||
expect(
|
expect(
|
||||||
@ -207,6 +210,9 @@ describe('ColorPicker', () => {
|
|||||||
expect(
|
expect(
|
||||||
container.querySelector('.ant-color-picker-alpha-input input')?.getAttribute('value'),
|
container.querySelector('.ant-color-picker-alpha-input input')?.getAttribute('value'),
|
||||||
).toEqual('2%');
|
).toEqual('2%');
|
||||||
|
expect(container.querySelectorAll('.ant-color-picker-presets-color')[9]).toHaveClass(
|
||||||
|
'ant-color-picker-presets-color-checked',
|
||||||
|
);
|
||||||
|
|
||||||
expect(handleColorChange).toHaveBeenCalledTimes(2);
|
expect(handleColorChange).toHaveBeenCalledTimes(2);
|
||||||
});
|
});
|
||||||
|
@ -53,38 +53,31 @@ const ColorPresets: FC<ColorPresetsProps> = ({ prefixCls, presets, value: color,
|
|||||||
onChange?.(colorValue);
|
onChange?.(colorValue);
|
||||||
};
|
};
|
||||||
|
|
||||||
const items: CollapseProps['items'] = useMemo(
|
const items: CollapseProps['items'] = presetsValue.map((preset) => ({
|
||||||
() =>
|
key: `panel-${preset.label}`,
|
||||||
presetsValue.map((preset) => ({
|
label: <div className={`${colorPresetsPrefixCls}-label`}>{preset?.label}</div>,
|
||||||
key: `panel-${preset.label}`,
|
children: (
|
||||||
label: <div className={`${colorPresetsPrefixCls}-label`}>{preset?.label}</div>,
|
<div className={`${colorPresetsPrefixCls}-items`}>
|
||||||
children: (
|
{Array.isArray(preset?.colors) && preset.colors?.length > 0 ? (
|
||||||
<div className={`${colorPresetsPrefixCls}-items`}>
|
preset.colors.map((presetColor: Color) => (
|
||||||
{Array.isArray(preset?.colors) && preset.colors?.length > 0 ? (
|
<ColorBlock
|
||||||
preset.colors.map((presetColor: Color) => (
|
key={`preset-${presetColor.toHexString()}`}
|
||||||
<ColorBlock
|
color={generateColor(presetColor).toRgbString()}
|
||||||
key={`preset-${presetColor.toHexString()}`}
|
prefixCls={prefixCls}
|
||||||
color={generateColor(presetColor).toRgbString()}
|
className={classNames(`${colorPresetsPrefixCls}-color`, {
|
||||||
prefixCls={prefixCls}
|
[`${colorPresetsPrefixCls}-color-checked`]:
|
||||||
className={classNames(`${colorPresetsPrefixCls}-color`, {
|
presetColor.toHexString() === color?.toHexString(),
|
||||||
[`${colorPresetsPrefixCls}-color-checked`]:
|
[`${colorPresetsPrefixCls}-color-bright`]: isBright(presetColor, colorBgElevated),
|
||||||
presetColor.toHexString() === color?.toHexString(),
|
})}
|
||||||
[`${colorPresetsPrefixCls}-color-bright`]: isBright(
|
onClick={() => handleClick(presetColor)}
|
||||||
presetColor,
|
/>
|
||||||
colorBgElevated,
|
))
|
||||||
),
|
) : (
|
||||||
})}
|
<span className={`${colorPresetsPrefixCls}-empty`}>{locale.presetEmpty}</span>
|
||||||
onClick={() => handleClick(presetColor)}
|
)}
|
||||||
/>
|
</div>
|
||||||
))
|
),
|
||||||
) : (
|
}));
|
||||||
<span className={`${colorPresetsPrefixCls}-empty`}>{locale.presetEmpty}</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
),
|
|
||||||
})),
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={colorPresetsPrefixCls}>
|
<div className={colorPresetsPrefixCls}>
|
||||||
|
Loading…
Reference in New Issue
Block a user