Skip to content

Commit e113bb0

Browse files
committed
chore: do not clear selection on escape, clear on backspace
1 parent 279452a commit e113bb0

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

packages/pluggableWidgets/combobox-web/src/components/SingleSelection/SingleSelection.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ export function SingleSelection({
2626
getMenuProps,
2727
reset,
2828
isOpen,
29-
highlightedIndex
29+
highlightedIndex,
30+
inputValue,
31+
selectItem
3032
} = useDownshiftSingleSelectProps(selector, options, a11yConfig.a11yStatusMessage);
3133
const inputRef = useRef<HTMLInputElement>(null);
3234
const lazyLoading = selector.lazyLoading ?? false;
@@ -66,7 +68,12 @@ export function SingleSelection({
6668
readOnly: selector.options.filterType === "none",
6769
ref: inputRef,
6870
"aria-required": ariaRequired.value,
69-
"aria-label": !hasLabel && options.ariaLabel ? options.ariaLabel : undefined
71+
"aria-label": !hasLabel && options.ariaLabel ? options.ariaLabel : undefined,
72+
onKeyDown: e => {
73+
if (e.key === "Backspace" && inputValue === "") {
74+
selectItem(null);
75+
}
76+
}
7077
},
7178
{ suppressRefError: true }
7279
);

packages/pluggableWidgets/combobox-web/src/hooks/useDownshiftSingleSelectProps.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export function useDownshiftSingleSelectProps(
9494
case useCombobox.stateChangeTypes.FunctionCloseMenu:
9595
return {
9696
...changes,
97+
selectedItem: state.selectedItem,
9798
isOpen: false,
9899
inputValue: ""
99100
};

0 commit comments

Comments
 (0)