ColorPicker : Fix inconsistent HEX input clearing behavior#77912
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
mirka
left a comment
There was a problem hiding this comment.
The fix looks good to me, thanks.
We'll also want a test to cover this, and also a changelog entry.
|
@mirka Thank you so much for review and suggestion, as per suggestion i have added relevant test case to cover this and also added CHANGELOG entry, Please have a look once 🙌. |
|
@mirka performance checks are timing out (again), do you think we can skip CI checks and force merge? |
What?
Closes #75243
This PR ensures that the
ColorPickercomponent consistently resets to black when its HEX input field is cleared, regardless of whether the deletion happens character by character or in a single action (e.g., selecting all and deleting).Why?
Previously, clearing the HEX input in a single action would trigger an early return in the
handleChangefunction because of a falsy value check. This left the previously selected color active in the picker despite the input field being empty, causing user confusion. By strictly checking forundefined, we allow the empty string to be processed, resulting in a consistent fallback to black.How?
The logic in
packages/components/src/color-picker/hex-input.tsxwas modified to change the early return condition fromif ( ! nextValue )toif ( nextValue === undefined ). This ensures that empty strings (which are falsy) are passed tocolord(), which handles invalid/empty strings by defaulting to black. Unit tests inpackages/components/src/color-picker/test/index.tsxwere also updated to reflect the additionalonChangecall triggered by the field clearance.Testing Instructions
ColorPicker(e.g., a Paragraph block's text color).Cmd+AorCtrl+A) and pressBackspaceorDelete.#000000.Testing Instructions for Keyboard
ColorPickerand navigate to the HEX input field.f00).Cmd+A(Mac) orCtrl+A(Windows) to select the text.Backspace.#000000.Screenshots or screencast
Before Fix :
ColorPicker-issue.mov
After Fix :
after-fix.mov
Use of AI Tools
AI is used to draft PR description.