Skip to content

fix: Make ColorPicker properly commit its new value upon clicking outside the dialog#9768

Merged
LFDanLu merged 3 commits intomainfrom
9748
Mar 10, 2026
Merged

fix: Make ColorPicker properly commit its new value upon clicking outside the dialog#9768
LFDanLu merged 3 commits intomainfrom
9748

Conversation

@LFDanLu
Copy link
Member

@LFDanLu LFDanLu commented Mar 9, 2026

Closes #9748
This also fixes the issue that #9646 covered in a different way

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

ColorPicker

  1. Open a S1 ColorPicker in the storybook
  2. Modify the ColorField to a complete value
  3. Click outside the dialog. Verify that the color properly changed

ComboBox

  1. Open the ComboBox in Dialog story in S2 Storybook
  2. Open the Dialog and ComboBox in said Dialog. Clicking on the Dialog's underlay should close the ComboBox popover

useDialog

  1. Go to the v3 useDialog docs in FireFox
  2. Open the Dialog and click outside it to dismiss it.
  3. Make sure text selection isn't active aka moving your cursor around should be selecting the docs text

🧢 Your Project:

RSP

@rspbot
Copy link

rspbot commented Mar 9, 2026

let dismissButtons = within(tray).getAllByRole('button');
switch (Method) {
case 'clicking outside tray':
await user.click(document.body);
Copy link
Member

Choose a reason for hiding this comment

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

why not leave as user.click?

Copy link
Member Author

Choose a reason for hiding this comment

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

Seems to break the react 16/17 tests

Copy link
Member

Choose a reason for hiding this comment

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

but... why?

Copy link
Member Author

Choose a reason for hiding this comment

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

alright I did some more digging, best I can tell in React 17/16

displayValue !== lastValueRef.current &&
(props.inputValue === undefined || value === undefined)
) {
resetInputValue();
} else if (lastValue !== inputValue) {
setLastValue(inputValue);
}
is running in different fashion based on if we use userEvent.click or fireEvent. With userEvent, the tracked displayValue and lastValueRef.current become out of sync versus fireEvent keeping these two in sync (aka both become null due to a custom value commit). If I had to hazard a guess, there is probably an extra commit or something happening which the current useEffect in useComboBoxState is fragile against. We should probably revisit that hook in general (and have talked about that for ages now haha) but its out of scope of this PR IMO.

As an aside, adding the extra click event doesn't cause the test to fail so it seems to be something specific to how userEvent.click works

@LFDanLu LFDanLu added this pull request to the merge queue Mar 10, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 10, 2026
@LFDanLu LFDanLu added this pull request to the merge queue Mar 10, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 10, 2026
@LFDanLu LFDanLu added this pull request to the merge queue Mar 10, 2026
Merged via the queue into main with commit fd415a9 Mar 10, 2026
29 checks passed
@LFDanLu LFDanLu deleted the 9748 branch March 10, 2026 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ColorPicker's color field doesn't commit its value if the popover is dismissed via outside click

5 participants