question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Combobox] Controlled component doesn't close popover on select

See original GitHub issue

🐛 Bug report

Current Behavior

When a value is selected on a controlled Combobox the onSelect callback fires but the popover does not close

Expected behavior

The popover should close when an item is selected

Reproducible example

https://codesandbox.io/s/musing-thunder-rmzvv

Suggested solution(s)

It seems this was introduced in https://github.com/reach/reach-ui/commit/d3836a67c7072f4277ef47078737fc3962d82b29 when the callbacks went from being fired before an action was sent to the reducer to them being called inside the reducer. This means that the combobox context value updates before the controlled value which triggers a state where the combobox receives a change in controlled value and reopens the popover immediately after closing it.

I think the best solution would be in a controlled component to never update the combobox context’s internal value except in the controlled component specific handleValueChange in ComboboxInput. This would require setting some sort of “controlled” flag in the combobox state but would prevent future race conditions like this.

Additional context

Your environment

Software Name(s) Version
Reach Package @reach/combobox 0.8.4
React 16.11.0
Browser Multiple
Assistive tech N/A
Node N/A
npm/yarn yarn 1.19.1
Operating System Multiple

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
chaancecommented, Dec 9, 2021

I’d recommend downgrading for the moment, I’m still working on this one as time allows. Sorry about that!

The latest update fixed another bug but seems to have caused a regression here, so I need to make sure they are both resolved before I release the next patch.

0reactions
tomstaveleycommented, May 25, 2022

I’m seeing this behaviour from v0.16.0 onwards.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Popover closing on selection of ComboBox - Stack Overflow
Means, you need to refocus the PopOver after user interaction or loading data immediately. The auto closing feature of PopOver is using a...
Read more >
Combobox - Reach UI
Accessible combobox (autocomplete or autosuggest) component for React. ... elements inside the popover, it won't close when the user interacts with them.
Read more >
ion-select: Select One or Multiple Value Boxes or Placeholders
ion-select is represented by selected value(s), or a placeholder, and dropdown icon. When you tap select, a dialog box appears with an easy...
Read more >
Dropdown - Multiselect - Carbon Design System
It is a stylized version of the select component, and can be styled as needed. ... Unlike dropdown and combo box, the menu...
Read more >
useSelect – React Aria
> is used to render a hidden native <select> , which enables browser form autofill support. The same Popover , ListBox , and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found