diff --git a/.changeset/big-beers-wash.md b/.changeset/big-beers-wash.md new file mode 100644 index 000000000..f1cd47c5b --- /dev/null +++ b/.changeset/big-beers-wash.md @@ -0,0 +1,5 @@ +--- +'@cube-dev/ui-kit': patch +--- + +Fix ComboBox behavior on choosing option via Enter press. diff --git a/src/components/fields/ComboBox/ComboBox.tsx b/src/components/fields/ComboBox/ComboBox.tsx index 6a9cc586e..a76daa46e 100644 --- a/src/components/fields/ComboBox/ComboBox.tsx +++ b/src/components/fields/ComboBox/ComboBox.tsx @@ -336,7 +336,13 @@ export const ComboBox = forwardRef(function ComboBox( if (e.key === 'Enter') { if (!props.allowsCustomValue) { if (state.isOpen) { + // If there is a selected option then do nothing. It will be selected on Enter anyway. + if (listBoxRef.current?.querySelector('li[aria-selected="true"]')) { + return; + } + const option = [...state.collection][0]?.key; + if (option && selectedKey !== option) { props.onSelectionChange?.(option);