Skip to content

Commit

Permalink
fix: keep combobox empty on tab
Browse files Browse the repository at this point in the history
  • Loading branch information
stdavis committed Mar 8, 2023
1 parent 5388608 commit b6268bd
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions _src/react-app/components/ComboBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ const ComboBox = React.forwardRef(function ComboBox({ items, onChange, value, id
},
itemToString: (item) => (item ? item.label : ''),
selectedItem: items.filter((item) => item.value === value)[0] || '',
stateReducer: (_, actionAndChanges) => {
stateReducer: (state, actionAndChanges) => {
const { type, changes } = actionAndChanges;
// clear input on blur if there is no selected item
if (type === useCombobox.stateChangeTypes.InputBlur && changes.inputValue !== changes.selectedItem?.label) {
// clear input on blur if there is no selected item or if the input value is empty
if (
type === useCombobox.stateChangeTypes.InputBlur &&
(changes.inputValue !== changes.selectedItem?.label || state.inputValue === '')
) {
setInputItems(items);
return {
...changes,
Expand Down

0 comments on commit b6268bd

Please sign in to comment.