Repository navigation
fix(color-picker): restore the opening value when Escape closes the popover (closes #1554) - #1555
Conversation
…opover (closes #1554) Every interaction applies the colour immediately, and the picker kept no record of the value it opened with, so Escape closed the popover with the new colour still applied. Text typed into the input was also applied on Escape, through the input's change event on blur. Save the value and format when the popover opens and restore both on Escape, resetting the input text so the blur is a no-op. The listener sits on window in the capture phase: WebKit doesn't focus clicked buttons, and the input stops keydown propagation. Closing any other way keeps the picked colour. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
nielslyngsoe
left a comment
There was a problem hiding this comment.
A bit excessive by adding this aspect to the element description, but otherwise fair fix and it works at is should, I tried all the various focus/click combinations to cheat it and it worked as it should.
But trying to navigate this via keyboard showed other problems of this component, which are important to resolve in relation to this fix.
I cannot submit my changes via the keyboard.
From a bit of investigation it turns out that Enter should commit and close. and if focus goes outside, like tabbing out, the popover should also commit and close. — this does not hapeen today so a keyboard user is a bit stuck.
One valueable feedback from Claude on this:
- Ignore Enter while typing with an IME
For example, a Japanese user types “aka” and sees あか → 赤 in a candidate list. They press Enter to pick 赤. If your keydown handler treats that Enter as “commit and close the popover”, it closes before they’ve finished typing.
During composition the browser sets event.isComposing = true, so skip those.
Keyboard users had no way to accept a colour and close the popover: Enter did nothing outside the text input, and tabbing out left the popover open. - Enter in the input, colour area, sliders or swatches keeps the change and closes the popover. Enter on the format and eyedropper buttons keeps its own action. The close is deferred: closing during keydown returns focus to the trigger, which then gets the same Enter and reopens the popover (seen in WebKit). - Enter that confirms an IME composition is ignored. - Moving focus out of the popover keeps the change and closes it. A focusout with no relatedTarget (window blur, or a click on something not focusable, as in Safari) keeps it open. - Drop the Escape note from the element description. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…loses the popover Chromium skips the native focus return for a popover inside a shadow root, and WebKit has nothing to return to when the popover was opened by a click. Focus also lingers on the hidden control before the browser moves it to body, so the check covers both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|



Description
Pressing Escape in the
uui-color-pickerpopover now restores the value (and format) the picker had when it opened. Closing it any other way keeps the picked colour, and the keyboard now has a way to do that too.Escape cancels
beforetoggle).setColor, which fireschangewith the restored value.windowin the capture phase, for two reasons. WebKit doesn't focus clicked buttons (swatches, the format toggle), so focus can be outside the popover. And the colour picker's inputkeydownhandler callsstopImmediatePropagation. I checked both by swapping the listener: a bubblingwindowlistener misses Escape from the input, and a listener on the popover misses it in WebKit after a swatch click.disconnectedCallback. Removing a popover that's open doesn't firebeforetoggle.Enter and tabbing out keep the change and close (from review)
focusoutwith norelatedTarget(switching window, or Safari not focusing a clicked swatch) leaves it open.Focus goes back to the trigger after Escape or Enter
body. That also happened with the plain native Escape before this PR.body, so the check covers both. Tabbing out and clicking outside leave focus alone.The
inlinemode is unchanged, since it has no popover.Closes #1554
Types of changes
Motivation and context
Every interaction applies the colour at once and fires
change, and the picker kept no record of the value it opened with. So Escape closed the popover with the new colour still applied. It was slightly worse than reported: text typed into the input and then dismissed with Escape was applied too, through the input'schangeon blur. For example, typingredand pressing Escape saved#ff0000.In the CMS this is the Eye Dropper Color Picker property editor (
umb-input-eye-dropper), which uses the popover mode. CMS 17.8 ships UUI^2.1.1, so a fix onmainreaches it. The Tiptap toolbar colour picker usesinlineand is not affected.Not in this PR: OK/Cancel buttons, which the issue mentions as a nice-to-have. That would be a feature, not this fix.
How to test?
In Storybook, open the colour picker's default story:
redinto the input without pressing Enter, then press Escape: the value is unchanged.redinto the input and press Enter: the value is#ff0000, the popover closes and the trigger has focus. The same goes for Enter on a swatch, the colour area or a slider.Automated: 15 new tests in
color-picker.test.ts, passing in Chromium and WebKit locally, and in Firefox on CI for the earlier commits. The full Chromium suite passes (1,114 tests). Firefox wouldn't start locally. Not covered: Escape while the nativeEyeDropperis open, which needs a real pick by a person, and a real IME composition (the test uses a syntheticisComposingevent).Screenshots (if appropriate)
Checklist
🤖 Generated with Claude Code