File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -32,10 +32,18 @@ export function useColorManipulation<T extends AnyColor>(
32
32
// Trigger `onChange` callback only if an updated color is different from cached one;
33
33
// save the new color to the ref to prevent unnecessary updates
34
34
useEffect ( ( ) => {
35
- let newColor ;
35
+ const { a, ...hsv } = hsva ;
36
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
37
+ const { a : _ , ...cacheHsv } = cache . current . hsva ;
38
+
39
+ // When alpha channel is changed, use cached RGB values to prevent rounding errors
40
+ const newColor = equalColorObjects ( hsv , cacheHsv )
41
+ ? Object . assign ( { } , cache . current . color , { a } )
42
+ : colorModel . fromHsva ( hsva ) ;
43
+
36
44
if (
37
45
! equalColorObjects ( hsva , cache . current . hsva ) &&
38
- ! colorModel . equal ( ( newColor = colorModel . fromHsva ( hsva ) ) , cache . current . color )
46
+ ! colorModel . equal ( newColor , cache . current . color )
39
47
) {
40
48
cache . current = { hsva, color : newColor } ;
41
49
onChangeCallback ( newColor ) ;
You can’t perform that action at this time.
0 commit comments