Skip to content

Commit

Permalink
feat(app): Search on enter (#1184)
Browse files Browse the repository at this point in the history
* Update SearchBox.tsx

* fix type var

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Joe Karow <[email protected]>
  • Loading branch information
3 people authored Mar 25, 2024
1 parent b369351 commit 70013b8
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/ui/components/core/SearchBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Trans, useTranslation } from 'next-i18next'
import {
type Dispatch,
forwardRef,
type KeyboardEventHandler,
type ReactNode,
type SetStateAction,
useDebugValue,
Expand Down Expand Up @@ -349,6 +350,15 @@ export const SearchBox = ({
}
}

const handleKeyDown: KeyboardEventHandler<HTMLInputElement> = (event) => {
if (event.key === 'Enter') {
const topItem = results[0]
if (topItem) {
selectionHandler(topItem)
}
}
}

return (
<Autocomplete
classNames={{
Expand All @@ -364,6 +374,7 @@ export const SearchBox = ({
dropdownPosition='bottom'
radius='xl'
onItemSubmit={selectionHandler}
onKeyDown={handleKeyDown}
disabled={isLoading}
label={label}
withinPortal
Expand Down

0 comments on commit 70013b8

Please sign in to comment.