Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Work around downshift+autofocus regression #9049

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/app/search/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,12 @@ function SearchBar(
) {
const { type, changes } = actionAndChanges;
switch (type) {
// FIXME: Do not act on focus because it interacts badly with autofocus
// Downshift will likely switch away from using focus because too
// https://github.com/downshift-js/downshift/issues/1439
// (Also see onFocus below)
case useCombobox.stateChangeTypes.InputFocus:
return state;
case useCombobox.stateChangeTypes.ItemClick:
case useCombobox.stateChangeTypes.InputKeyDownEnter:
// exit early if non FilterHelper item was selected
Expand All @@ -316,14 +322,15 @@ function SearchBar(
return {
...changes,
selectedItem: state.selectedItem, // keep the last selected item (i.e. the edit field stays unchanged)
closeMenu: true, // close the menu
Copy link
Member Author

Choose a reason for hiding this comment

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

This is not advertised in the types and Downshift doesn't seem to read it.

};

default:
return changes; // no handling for other types
}
}

// FIXME: Maybe follow suit when Downshift changes opening behavior to
// just use clicks and not focus (see stateReducer above)
const onFocus = () => {
if (!liveQuery && !isOpen && !autoFocus) {
openMenu();
Expand Down