gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

ColorPicker : Inconsistent behavior of default color when cleared one by one character and when cleared in one action

Open dpmehta opened this issue 9 months ago • 2 comments

Description

While working with Gutenberg ColorPicker, i noticed an inconsistent behavior when removing the HEX value from input field. If we select any color from picker and if we remove it character by character then it defaults to black but if we choose whole HEX at once and clear then it defaults to whatever previously selected and also HEX value is cleared but color still remains selected in picker which can create confusion for user because HEX value is cleared but still color is showing.

Step-by-step reproduction instructions

  1. Select any custom color in the ColorPicker.

  2. Focus the HEX input field.

  3. Remove the HEX value character by character using backspace.

    • Result: the selected color resets to black.
  4. Repeat the test, but this time:

    • Select the full HEX value
    • Delete it in single action
    • Result: the previously selected color remains active

Screenshots, screen recording, code snippet

https://github.com/user-attachments/assets/1ebc2313-00a7-457d-9f87-642609d8ff81

Environment info

WordPress Version : 6.9 Gutenber Version : 22.5.0-rc.1

Please confirm that you have searched existing issues in the repo.

  • [x] Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • [x] Yes

Please confirm which theme type you used for testing.

  • [x] Block
  • [ ] Classic
  • [ ] Hybrid (e.g. classic with theme.json)
  • [ ] Not sure

dpmehta avatar Feb 05 '26 12:02 dpmehta

I was able to reproduce this issue. Working on this one. Will share my findings here if I found anything.

Mustafabharmal avatar Feb 05 '26 12:02 Mustafabharmal

Issue related to this : while i was working in another work in which i need to add ColorPicker component to provide custom functionality and i want something like if user clears HEX value and save Post then i want to have default color say for example #3C3941 as selected but i am not able to do that due to the issue mentioned above.

I have already tried defaultValue param but its also not working.

Suppose #ff00ff was already selected and if i clears it character by character and if i save post then it default to #000 but i want #3C3941 and if i select whole HEX at once and clear and save POST then previously selected (#ff00ff) is selected which is again not wanted as it should be #3C3941.

<ColorPicker
         color={color}
         onChange={setColor}
         enableAlpha
         defaultValue="#3C3941"
/>

dpmehta avatar Feb 05 '26 12:02 dpmehta