Skip to content

ColorSwatchPicker always selects #000 when in "unselected" state. #7918

@MaikuMori

Description

@MaikuMori

Provide a general summary of the issue here

If the Swatch contains color #000, there is no way to unselect it.

This is due to: https://github.com/adobe/react-spectrum/blob/main/packages/react-aria-components/src/ColorSwatchPicker.tsx#L44

See CodeSandBox link at bottom for a better explanation.

🤔 Expected Behavior?

The value should accept null or undefined and properly handle that.

😯 Current Behavior

<ColorSwatchPicker>
  <ColorSwatch color={"#000"} />
  <ColorSwatch color={"#F00"} />
</ColorSwatchPicker>

Will show #000 as selected.

💁 Possible Solution

The value should accept null or undefined and properly handle that.

🔦 Context

I have a ColorSwatchPicker where the list of colors is user defined. I know the hacky workaround is to just set the value to a non-existent color in the list, but that's very wrong.

🖥️ Steps to Reproduce

Here's a CodeSandBox outlining a couple issues with the current implementation:

https://codesandbox.io/p/sandbox/exciting-waterfall-h66ngf

Version

latest

What browsers are you seeing the problem on?

Other

If other, please specify.

all

What operating system are you using?

mac

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions