From 98c9aa0ce20f3544d72ae86cbed14ab2408b7ef3 Mon Sep 17 00:00:00 2001 From: huangchen1031 Date: Fri, 29 Nov 2024 16:03:54 +0800 Subject: [PATCH] =?UTF-8?q?fix(color-picker):=20=E4=BF=AE=E5=A4=8DinnerVal?= =?UTF-8?q?ue=E5=92=8CcolorInstanceRef=E4=B8=8D=E5=90=8C=E6=AD=A5=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/color-picker/components/panel/index.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/color-picker/components/panel/index.tsx b/src/color-picker/components/panel/index.tsx index b251c3bd53..ae6c4a884f 100644 --- a/src/color-picker/components/panel/index.tsx +++ b/src/color-picker/components/panel/index.tsx @@ -56,7 +56,6 @@ const Panel = forwardRef((props, ref) => { const [recentlyUsedColors, setRecentlyUsedColors] = useControlled(props, 'recentColors', onRecentColorsChange, { defaultRecentColors: colorPickerDefaultProps.recentColors, }); - const colorInstanceRef = useRef(new Color(innerValue || defaultEmptyColor)); const getModeByColor = colorInstanceRef.current.isGradient ? 'linear-gradient' : 'monochrome'; const formatRef = useRef(colorInstanceRef.current.isGradient ? 'CSS' : format ?? 'RGB'); @@ -80,12 +79,14 @@ const Panel = forwardRef((props, ref) => { const emitColorChange = useCallback( (trigger?: ColorPickerChangeTrigger) => { - setInnerValue(formatValue(), { + const value = formatValue(); + setInnerValue(value, { color: getColorObject(colorInstanceRef.current), trigger: trigger || 'palette-saturation-brightness', }); + update(value); }, - [formatValue, setInnerValue], + [formatValue, setInnerValue, update], ); useEffect(() => {