Skip to content

fix(color-picker): ensure color change is emitted with updated mode #3493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 10, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/components/color-picker/components/panel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ const Panel = forwardRef<HTMLDivElement, ColorPickerProps>((props, ref) => {

const formatValue = useCallback(() => {
// 渐变模式下直接输出css样式
if (mode === 'linear-gradient') {
if (colorInstanceRef.current.isGradient) {
return colorInstanceRef.current.linearGradient;
}
const finalFormat = format === 'HEX' && enableAlpha ? 'HEX8' : format; // hex should transfer to hex8 when alpha channel is opened
return colorInstanceRef.current.getFormatsColorMap()[finalFormat] || colorInstanceRef.current.css;
}, [format, enableAlpha, mode]);
}, [format, enableAlpha]);

const emitColorChange = useCallback(
(trigger?: ColorPickerChangeTrigger) => {
Expand Down Expand Up @@ -129,10 +129,12 @@ const Panel = forwardRef<HTMLDivElement, ColorPickerProps>((props, ref) => {
const { rgba, gradientColors, linearGradient } = colorInstanceRef.current;
if (value === 'linear-gradient') {
colorInstanceRef.current = new Color(gradientColors.length > 0 ? linearGradient : DEFAULT_LINEAR_GRADIENT);
return;
} else {
colorInstanceRef.current = new Color(rgba);
}
colorInstanceRef.current = new Color(rgba);
emitColorChange();
};

// 最近使用颜色变更时触发
const handleRecentlyUsedColorsChange = (colors: string[]) => {
setRecentlyUsedColors(colors);
Expand Down
Loading