fix(SW-1115) trigger search
This commit is contained in:
@@ -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",
|
||||
})}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user