casesandberg / casesandberg/react-color

There might be wrong usage in the `examples/basic-with-react-hooks`, that will cause the <Alpha/> component not working.

Open
#845 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
12.3k
Forks
920
PR merge metrics
No merged PRs in 30d

Description

When I try it out the demo using `SketchPicker`, I found out that the `Alpha` handle is not working.

After digging for a while I found the usage from the demo is wrong.

```
// In the demo
const [color, setColor] = useState();
const handleChange = color => setColor(color);
return (




);
```
WeChat325b7dd1d9b44f7c3884da1396911acd
WeChat8d20778a8b3a3c2a70504a42fe1e4bda

After adding some logs in the source code(helpers/color.js -> toState()), you can see the `onChange` callback pass a color object to the setColor, which includes a param named `hex`, and that will cause the `toState` function to handle it as a pure hex, so the alpha is lost.

It should be used like this:

```
// In the demo
const [color, setColor] = useState();
const handleChange = color => setColor(color.rgb);
return (




);
```

Contributor guide

Open the contributing guide

Research direction

Start in examples/basic-with-react-hooks and compare its SketchPicker state handling with the callback behavior described in the issue. Read helpers/color.js, especially toState(), then update the demo usage so the Alpha value is preserved and verify that the picker displays transparency correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.