Skip to content

fix(color-picker): restore the opening value when Escape closes the popover (closes #1554) - #1555

Merged
nielslyngsoe merged 3 commits into
mainfrom
claude/issue-1554-fix-f51102
Nov 19, 2026
Merged

nielslyngsoe merged 3 commits into
mainfrom
claude/issue-1554-fix-f51102

Conversation

@iOvergaard

@iOvergaard iOvergaard commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Description

Pressing Escape in the uui-color-picker popover 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

  • The value and format are saved when the popover opens (beforetoggle).
  • While the popover is open, an Escape listener puts them back through setColor, which fires change with the restored value.
  • The input text is reset to the committed value, so any typed-but-uncommitted text isn't applied when the input loses focus.
  • The listener sits on window in 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 input keydown handler calls stopImmediatePropagation. I checked both by swapping the listener: a bubbling window listener misses Escape from the input, and a listener on the popover misses it in WebKit after a swatch click.
  • The listener is removed when the popover closes and in disconnectedCallback. Removing a popover that's open doesn't fire beforetoggle.

Enter and tabbing out keep the change and close (from review)

  • Enter in the text field, the colour area, the sliders and the swatches keeps the change and closes the popover. Enter on the format and eyedropper buttons inside the input still only does their own thing.
  • Enter while an IME is composing is ignored.
  • The close on Enter is deferred: in WebKit, closing during the keydown returns focus to the trigger, which then gets the same Enter and reopens the popover.
  • Moving focus out of the popover (Tab) closes it and keeps the change. A focusout with no relatedTarget (switching window, or Safari not focusing a clicked swatch) leaves it open.

Focus goes back to the trigger after Escape or Enter

  • Chromium skips the native focus return for a popover inside a shadow root, so focus fell to body. That also happened with the plain native Escape before this PR.
  • WebKit has nothing to return to when the popover was opened by a click, since the click doesn't focus the trigger.
  • Focus stays on the hidden control for a moment before the browser moves it to body, so the check covers both. Tabbing out and clicking outside leave focus alone.

The inline mode is unchanged, since it has no popover.

Closes #1554

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (minor updates related to the tooling or maintenance of the repository, does not impact compiled assets)

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's change on blur. For example, typing red and 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 on main reaches it. The Tiptap toolbar colour picker uses inline and 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:

  1. Open the picker and pick a swatch, drag in the colour area, or move the hue slider. Press Escape: the trigger shows the original colour again, and has focus.
  2. Open it, type red into the input without pressing Enter, then press Escape: the value is unchanged.
  3. Open it, toggle the format to RGB, then press Escape: the format is back to HEX and the value is unchanged.
  4. Open it, pick a swatch, then click outside: the new colour is kept.
  5. Open it, type red into 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.
  6. Open it, tab into a swatch, then tab past the last control: the popover closes, the colour is kept, and focus is on the next element on the page.

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 native EyeDropper is open, which needs a real pick by a person, and a real IME composition (the test uses a synthetic isComposing event).

Screenshots (if appropriate)

Checklist

  • If my change requires a change to the documentation, I have updated the documentation in this pull request.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.

🤖 Generated with Claude Code

…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>
Copilot AI balanced review requested due to automatic review settings November 17, 2026 11:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@iOvergaard iOvergaard added the bug Something isn't working label Nov 18, 2026

@nielslyngsoe nielslyngsoe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

iOvergaard and others added 2 commits November 18, 2026 11:05
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>
@sonarqubecloud

Copy link
Copy Markdown

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

You can't cancel out of a Colour Picker (Eyedropper) change

3 participants