Skip to content

Commit

Permalink
fix(color-picker): 修复innerValue和colorInstanceRef不同步的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
huangchen1031 committed Nov 29, 2024
1 parent db1184b commit 98c9aa0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/color-picker/components/panel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const Panel = forwardRef<HTMLDivElement, ColorPickerProps>((props, ref) => {
const [recentlyUsedColors, setRecentlyUsedColors] = useControlled(props, 'recentColors', onRecentColorsChange, {
defaultRecentColors: colorPickerDefaultProps.recentColors,
});

const colorInstanceRef = useRef<Color>(new Color(innerValue || defaultEmptyColor));
const getModeByColor = colorInstanceRef.current.isGradient ? 'linear-gradient' : 'monochrome';
const formatRef = useRef<TdColorPickerProps['format']>(colorInstanceRef.current.isGradient ? 'CSS' : format ?? 'RGB');
Expand All @@ -80,12 +79,14 @@ const Panel = forwardRef<HTMLDivElement, ColorPickerProps>((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(() => {
Expand Down

0 comments on commit 98c9aa0

Please sign in to comment.