hxf31891 / react-gradient-color-picker

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

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

Closed artrointel closed 2 weeks ago

artrointel commented 3 months 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 3 months ago

👍🏼 +1

hxf31891 commented 2 weeks ago

@artrointel @seungwan-woo this should be fixed in v3.0.11 I am going to close but if you find anymore issues or continue getting the behaviour please reopen.