Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8 character hex alpha breaks slider at 0 #33

Closed
frankie-swrve opened this issue Jan 13, 2022 · 3 comments
Closed

8 character hex alpha breaks slider at 0 #33

frankie-swrve opened this issue Jan 13, 2022 · 3 comments

Comments

@frankie-swrve
Copy link

frankie-swrve commented Jan 13, 2022

My Environment

MacOS 11.6 (2017 15-inch)
2.8ghz Quad-Core Intel Code i7
Radeon Pro 555 2GB / Intel HD 630 1536 MB

Dependency Version
Node.JS version v10.24.1
react-color-palette version v6.1.0

Expected Behavior:

The slider should be at the zero position for an 8 character hex, i.e. #12345600

Actual Behavior:

Slider resets to full position when alpha channel set to 0 via hex

Additional Context:

Appears to be an issue with the HSV as a perfect 0 returns 'undefined' in the hsv.a position

@frankie-swrve
Copy link
Author

frankie-swrve commented Jan 13, 2022

Appears to also happen with RGB value.

So if you use the slider to set the value, the rgb.a and hsv.a will be set to 0, but when you open a pop up again with the same value, both will be undefined

so const [color, setColor] = useColor('hex', value) where value = '#12345600' will not make the .a props 0, instead they will be 'undefined', but a hex of '#12345601' will set them to ~0.004

@frankie-swrve
Copy link
Author

  // Detect bad alpha value
  if (
    ((color.hex.length === 5 && color.hex.substring(4, 5) === '0') ||
      (color.hex.length === 9 && color.hex.substring(7, 9) === '00')) &&
    (color.rgb.a === undefined && color.hsv.a === undefined)
  ) {
    var _copy = color
    _copy.rgb.a = 0
    _copy.hsv.a = 0
    setColor(_copy)
  }

This solves the issue but I'd rather not have to detect this every time

@Wondermarin
Copy link
Owner

Fixed in v7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants