Skip to content

Commit

Permalink
clear internal dropdown state
Browse files Browse the repository at this point in the history
  • Loading branch information
macfarlandian committed Apr 15, 2021
1 parent 5fdb5e3 commit 8194030
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion spotlight-client/src/UiLibrary/Dropdown/DropdownBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ const DropdownBase: React.FC<
// helper for animation of menu opening and closing
const [waitForCloseAnimation, setWaitForCloseAnimation] = useState(false);

const { selectedItem, ...passThruSelectProps } = selectProps;

const {
closeMenu,
isOpen,
Expand All @@ -97,7 +99,11 @@ const DropdownBase: React.FC<
} = useSelect({
items: options,
onIsOpenChange: () => setWaitForCloseAnimation(true),
...selectProps,
// passing null explicitly clears the selection; without it,
// Downshift maintains an internal selection state that we don't want.
// The dropdown is either fully controlled by an input prop or it is stateless
selectedItem: selectedItem || null,
...passThruSelectProps,
});

// animate button hover state
Expand Down

0 comments on commit 8194030

Please sign in to comment.