hxf31891 / react-gradient-color-picker

An easy to use color/gradient picker for React.js
MIT License
138 stars 43 forks source link

Wrong behavior occurs around doing `or(||)` operation for null-safety. #104

Open artrointel opened 1 month ago

artrointel commented 1 month ago

We're suffering from common issues updating to a value 0 on this library. so we found some wrong operations in this project to achieve null-safety like below, but it now leads unintended behaviors.

const newValue = value || fallbackValue; // actual intention of a value can be 0, but the newValue cannot be updated to 0.

Recently, we've noticed that the user cannot update the gradient color position to 0 with the picker handle, and the root cause was here.

    const handleGradient = (newColor: string, left?: number) => { // this left can be undefined.
    const remaining = colors?.filter((c: ColorsProps) => !isUpperCase(c.value))
    const newColors = [
      { value: newColor.toUpperCase(), left: left || currentLeft }, // but the left can be 0 as well.
      ...remaining,
    ]
    createGradientStr(newColors)
  }

Also we've found some more codes doing like this on the project. please fix it.

seungwan-woo commented 1 month ago

👍🏼 +1