Open tjvg91 opened 4 years ago
Same issue for me. HandleChangeComplete returns the object with correct alpha, but the alpha in the SketchPicker keeps going back to 100 after clicking an alpha or entering via keyboard.
Same problem here.
This seems to be the issue: #416 The hex values do not have alpha yet.
I managed to solve the problem by using the rgba value when the alpha isn't 1.
const handleColorChange = (color: ColorResult) => {
let colorStr = color.hex
if(color.rgb.a !== 1){
colorStr = `rgba(${color.rgb.r}, ${color.rgb.g}, ${color.rgb.b}, ${color.rgb.a})`
}
// do something with colorStr...
}
Here is the solution for 8-digit hex code:
const decimalToHex = (alpha: number) => alpha === 0 ? '00' : Math.round(255 * alpha).toString(16)
const handleColorChange = (color: ColorResult) => {
const hexCode = `${c.hex}${decimalToHex(c.rgb.a)}`
}
Ah, yes, unfortunately this does not support having alphas on pre-defined swatches yet. I will track this in the 3.0.0 milestone to make sure it gets fixed in the new release.
keyboard
wow, i fixed it by your answer, thanks very much
when I change the color property, or change it by clicking the palette, the rgb values change, but not alpha.