Skip to content

Conversation

@mcsf
Copy link
Contributor

@mcsf mcsf commented Nov 11, 2025

What?

When the ColorPicker is open, let the user paste a colour value in any recognisable format. No particular input needs to have focus: pasting works anywhere in the picker. This works even if the format isn't supported by the UI (internal representation is hexadecimal).

  • When possible, the UI switches to the corresponding format (hex, RGB, HSL).
  • Recognisable formats are hexadecimal, RGB, HSL and colour names. Example inputs: #123, rgb(100 200 30), hsl(60, 20%, 80%), cyan
colorpicker-paste-1.mov
colorpicker-paste-2.mov

Why?

  • Pasting colors is cumbersome. Usually it requires that 1) they be converted to hex, 2) the instance of ColorPicker be switched to hex type, 3) so that finally a regular paste event can triggered in the text input. I expect it would deter many novice users using colours from a different application.
  • I believe that letting the UI switch to the provided format is also convenient, on the assumption that the user will want to make adjustments in the same format.

How?

  • Attach a capture-time listener to the picker component to intercept paste events.
  • If it succeeds in parsing the input as a colour, it will apply it .
    • If the input format is one of hex / RGB / HSL, switch to that type too.
  • Else let the event propagate normally.
    • This should be enough to let the input controls inside the picker work normally (e.g. when a user pastes a single component of a colour).

Testing instructions

  • Paste and verify correct application of:
    • hex colors (e.g. #ff0000)
    • rgb colors (e.g. rgb(255, 0, 0))
    • hsl colors (e.g. hsl(0, 100%, 50%))
    • named colors (e.g. "red", "cyan")
  • Paste invalid text and verify normal paste behaviour works in individual inputs
  • Test paste functionality across different ColorPicker instances

@mcsf mcsf requested a review from ajitbohra as a code owner November 11, 2025 16:26
@mcsf mcsf added [Type] Enhancement A suggestion for improvement. [Feature] Colors Color management labels Nov 11, 2025
@github-actions
Copy link

github-actions bot commented Nov 11, 2025

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: mcsf <[email protected]>
Co-authored-by: jorgefilipecosta <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Member

@jorgefilipecosta jorgefilipecosta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worked well on my tests and it is nice improvement for advanced users when they discover it.

@jorgefilipecosta
Copy link
Member

One thing we could also explore in a follow up would be to when the color popover is open:
Screenshot 2025-11-11 at 17 02 34

Accept a paste color event even without needing to open the custom color picker, that would speed up things even more.

@mcsf
Copy link
Contributor Author

mcsf commented Nov 11, 2025

One thing we could also explore in a follow up would be to when the color popover is open

Yeah, this came to my mind too. We could try it if this goes well. :)

@mcsf mcsf force-pushed the add/color-picker/color-pasting branch from 403fe35 to 3748996 Compare November 11, 2025 17:38
@github-actions
Copy link

Flaky tests detected in 3748996.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/19273841639
📝 Reported issues:

@mcsf mcsf merged commit f3624d8 into trunk Nov 11, 2025
34 checks passed
@mcsf mcsf deleted the add/color-picker/color-pasting branch November 11, 2025 20:52
@github-actions github-actions bot added this to the Gutenberg 22.1 milestone Nov 11, 2025
@hanneslsm
Copy link

hanneslsm commented Nov 19, 2025

Great work! Thanks for working on this! Closes partially #73166 #50502

One thing we could also explore in a follow up would be to when the color popover is open:

I also had this idea in #73166 #50502
If you like, feel free to reference to this issue then or create a new one. Whatever fits you better :)

@mcsf
Copy link
Contributor Author

mcsf commented Nov 19, 2025

Hey, @hanneslsm! I think you accidentally referenced this very PR (73166). Which issue does this partially close?

@hanneslsm
Copy link

Oops, yes I did! That's the issue I was talking about: #50502

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

Labels

[Feature] Colors Color management [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants