Skip to content

Commit

Permalink
feat(autocomplete): in trip planner, auto-select first result on enter (
Browse files Browse the repository at this point in the history
  • Loading branch information
thecristen authored Feb 5, 2025
1 parent b28074d commit d95d7c3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions assets/ts/ui/autocomplete/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,15 @@ const TRIP_PLANNER = ({
onReset: (): void => {
pushToLiveView({});
},
onSubmit({ state, setQuery }) {
// Triggered by pressing enter on the input: selects the first result.
const results = state.collections.flatMap(collection => collection.items);
if (results.length > 0) {
const item = results[0];
// @ts-ignore
onSelect({ item, setQuery });
}
},
getSources({ query }) {
if (!query)
return debounced([
Expand Down

0 comments on commit d95d7c3

Please sign in to comment.