Skip to content

Commit c969370

Browse files
cursoragentChmaraX
andcommitted
Fix: Prevent default on Enter and add fallback select
Co-authored-by: adam.chmara1 <[email protected]>
1 parent 3b45070 commit c969370

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

apps/dashboard/src/components/primitives/autocomplete.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export function Autocomplete<T extends AutocompleteItem>({
7070
// Form submission handler
7171
const handleSubmit = (e: React.FormEvent) => {
7272
e.preventDefault();
73+
e.stopPropagation();
7374

7475
if (open && hasResults && highlightedIndex >= 0) {
7576
// Select highlighted item
@@ -141,9 +142,12 @@ export function Autocomplete<T extends AutocompleteItem>({
141142
setOpen(false);
142143
break;
143144
case 'Enter':
145+
e.preventDefault();
144146
if (highlightedIndex >= 0) {
145-
e.preventDefault();
146147
handleSelectItem(items[highlightedIndex]);
148+
} else if (items.length > 0) {
149+
// If no item is highlighted but there are results, select the first item
150+
handleSelectItem(items[0]);
147151
}
148152
break;
149153
}

0 commit comments

Comments
 (0)