Skip to content

Commit 7250112

Browse files
authored
fix(ComboBox): on enter press behavior (#633)
1 parent 1ba6ea5 commit 7250112

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

.changeset/big-beers-wash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@cube-dev/ui-kit': patch
3+
---
4+
5+
Fix ComboBox behavior on choosing option via Enter press.

src/components/fields/ComboBox/ComboBox.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,13 @@ export const ComboBox = forwardRef(function ComboBox<T extends object>(
336336
if (e.key === 'Enter') {
337337
if (!props.allowsCustomValue) {
338338
if (state.isOpen) {
339+
// If there is a selected option then do nothing. It will be selected on Enter anyway.
340+
if (listBoxRef.current?.querySelector('li[aria-selected="true"]')) {
341+
return;
342+
}
343+
339344
const option = [...state.collection][0]?.key;
345+
340346
if (option && selectedKey !== option) {
341347
props.onSelectionChange?.(option);
342348

0 commit comments

Comments
 (0)