Skip to content

Commit

Permalink
Work around downshift focus regression
Browse files Browse the repository at this point in the history
  • Loading branch information
robojumper committed Feb 2, 2023
1 parent e8b1a88 commit 5685332
Showing 1 changed file with 8 additions and 1 deletion.
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
};

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

0 comments on commit 5685332

Please # to comment.