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] Respect openOnFocus property, and prevent popover close on input clear

See original GitHub issue

🚀 Feature request

Current Behavior

As per #655, currently when the combobox input is cleared (i.e. the value changes to an empty string) the combobox popover is closed.

This happens even when the openOnFocus prop is set to true. This leads to a strange interaction where,

  • when you first click/focus on the input the ComboboxPopover opens
  • then type something in the input, the popover remains open
  • and then delete the text from the input and the popover then closes even though the input still has focus

If you then focus on another element, then back to the input, the popover reopens - though again, nothing has changed in the input.

Desired Behavior

While the input is focused, the ComboboxPopover should always remain open, and should only close when focus is lost.

Suggested Solution

Either make the openOnFocus prop override the automatic close/hide functionality of the ComboboxPopover, or if that isn’t the intended behaviour, add a new prop such as keepOpenOnClear (which defaults to false) that can be used in conjunction with openOnFocus to prevent unwanted closing of the popover.

Who does this impact? Who is this for?

For developers who want all of the options displayed when there is the input is empty - which allows users to quickly select an option without necessarily needing to type. This functionality is already there when the Combobox is first focused, but is lost when the input is subsequently cleared.

Describe alternatives you’ve considered

As mentioned in #655, the workaround described in https://github.com/reach/reach-ui/issues/367#issuecomment-668889405 is unsatisfactory from a UX perspective.

Additional context

This was already requested in #367 and #655, but the issue was closed due to inactivity.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:4
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
geekuscommented, Apr 28, 2022

In my opinion, this (close on clear) is hardly a feature request, but rather unexpected behavior and a bug. Checking a few other similar plugins (react-select.com, select2.org, mui.com/material-ui/react-autocomplete, semantic-ui.com/modules/dropdown.html), they all stay open when field/value is cleared.

2reactions
indiesquidgecommented, Jan 4, 2021

Playing around with it more, I could see the value in wanting the popover to remain open when the input is cleared to show some results. The current workaround is to use the openOnFocus prop and, when the input is cleared, blur and re-focus the input to show the results.

I created a branch that keeps the popover visible even when the input is cleared when openOnFocus is true if you’d like to experiment with it.

I can’t decide if it’s a good solution to change the behavior of openOnFocus though. Technically speaking, openOnFocus does entirely what it claims to do: open the popover on focus. It makes no claims on what happens when the input is cleared, and adding that behavior could be unexpected/unwanted for some folks.

If this feature is something we’d like to support, perhaps it being a separate prop (e.g. closeOnClear,keepOpenOnClear, etc) would make more sense semantically and would avoid the unexpected additional behavior of openOnFocus doing more than opening on focus. However, I also don’t love the idea of having yet another boolean prop™ for this library to maintain and keep tabs on as things evolve.

@chaance I’d be curious to hear your thoughts on what to do here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Combobox - Reach UI
Accessible combobox (autocomplete or autosuggest) component for React. A combobox is the combination of an <input type="text"/> and a list. The list is...
Read more >
How to prevent MUI Autocomplete from closing when its input ...
It seems that whenever the autocomplete input looses focus it closes, is there any way to prevent this? const [isEdit, SetIsEdit] = useState( ......
Read more >
@khard/material-ui-0.18.7-popover-fix | Yarn - Yarn
Component Fixes / Enhancements · AppBar. IconButton styles are now being properly merged (#967) · DatePicker. Prevent root styles from propagating to child...
Read more >
CHANGELOG.md - TINMAN
`@material-ui/core@v3.4.0` - [Autocomplete] Fix react-select input overflow ... Prevent IE11 from crashing on modal close (#11115) @JonAbrams - [Input] Fix ...
Read more >
@reach/combobox: Versions | Openbase
This prevents unwanted layout shift when the server-rendered popover ... #757 If Combobox openOnFocus is true then also open when the input is...
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