Skip to content

fix: commit ColorField value on Enter, matching NumberField behavior (Fixes #10445) - #10446

Open
waterWang wants to merge 1 commit into
adobe:mainfrom
waterWang:fix/colorfield-enter-commit
Open

fix: commit ColorField value on Enter, matching NumberField behavior (Fixes #10445)#10446
waterWang wants to merge 1 commit into
adobe:mainfrom
waterWang:fix/colorfield-enter-commit

Conversation

@waterWang

Copy link
Copy Markdown

Summary

Pressing Enter in a ColorField now commits the typed value, matching the behavior of NumberField. Previously, typing a hex value and pressing Enter would silently retain the input display but not commit it to the color state — the value was only flushed on blur. If the user then closed a ColorPicker popover with Escape, the typed value was silently discarded and the previous color restored.

Implementation

Mirrors the useNumberField Enter handling pattern (useKeyboard with flushSync(() => commit())):

  • Added flushSync import from react-dom
  • Added useKeyboard import from ../interactions/useKeyboard
  • Added onKeyDown and onKeyUp to props destructuring
  • Added useKeyboard hook with an Enter shortcut that calls flushSync(() => commit())
  • Merged keyboardProps first in the mergeProps chain so shortcuts run before other handlers

Related

Test plan

  • Type a hex value into a ColorField and press Enter — value should be committed immediately
  • Type a hex value and press Escape — should NOT commit (cancel-on-Escape is conventional)
  • Tab out of the field — value should commit on blur (existing behavior, unchanged)
  • All existing tests should pass

@snowystinger snowystinger 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.

Thanks for the speedy PR
Please add tests, there are probably some in RAC NumberField that you can base them on.

Enter: () => {
flushSync(() => {
commit();
});

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.

I suspect we'll need the commitValidation as well so that it gets marked invalid before an implicit form submission

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ColorField: typed value is not committed on Enter and silently discarded on Escape dismissal

2 participants