fix(SW-1115) trigger search

This commit is contained in:
Pontus Dreij
2024-12-11 11:40:45 +01:00
parent 4b51b5aff6
commit 3c9aaa3dd3
7 changed files with 26 additions and 10 deletions

View File

@@ -27,8 +27,8 @@ import type { Location } from "@/types/trpc/routers/hotel/locations"
const name = "search"
export default function Search({ locations }: SearchProps) {
const { register, setValue, trigger, unregister } =
export default function Search({ locations, handlePressEnter }: SearchProps) {
const { register, setValue, unregister } =
useFormContext<BookingWidgetSchema>()
const intl = useIntl()
const value = useWatch({ name })
@@ -90,7 +90,6 @@ export default function Search({ locations }: SearchProps) {
setValue("location", encodeURIComponent(stringified))
sessionStorage.setItem(sessionStorageKey, stringified)
setValue(name, selectedItem.name)
trigger()
const searchHistoryMap = new Map()
searchHistoryMap.set(selectedItem.name, selectedItem)
@@ -165,6 +164,7 @@ export default function Search({ locations }: SearchProps) {
itemToString={(value) => (value ? value.name : "")}
onSelect={handleOnSelect}
onInputValueChange={(inputValue) => dispatchInputValue(inputValue)}
defaultHighlightedIndex={0}
>
{({
getInputProps,
@@ -209,6 +209,13 @@ export default function Search({ locations }: SearchProps) {
...register(name, {
onChange: handleOnChange,
}),
onKeyDown: (e) => {
if (e.key === "Enter") {
if (!isOpen) {
handlePressEnter()
}
}
},
type: "search",
})}
/>