Skip to content

Commit

Permalink
fix(ComboBox): retain input value when menu is open and esc is pressed
Browse files Browse the repository at this point in the history
  • Loading branch information
tw15egan committed Feb 17, 2023
1 parent ca262ed commit 00a61d2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 8 additions & 0 deletions packages/react/src/components/ComboBox/ComboBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,14 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
if (match(event, keys.Enter) && !inputValue) {
toggleMenu();
}

if (match(event, keys.Escape) && inputValue) {
if (event.target === textInput.current && isOpen) {
toggleMenu();
event.preventDownshiftDefault = true;
event.persist();
}
}
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,11 @@ const FilterableMultiSelect = React.forwardRef(function FilterableMultiSelect(
if (match(event, keys.Delete) || match(event, keys.Escape)) {
if (isOpen) {
handleOnMenuChange(true);
clearInputValue();
event.stopPropagation();
} else if (!isOpen) {
clearInputValue();
clearSelection();
event.stopPropagation();
if (event.target.value === '') {
clearSelection();
event.stopPropagation();
}
}
}
}
Expand Down

0 comments on commit 00a61d2

Please sign in to comment.