Skip to content

Commit

Permalink
handle keyword + enter press in search box
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalmi committed Aug 23, 2023
1 parent b49a1c5 commit 1d2f72d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/js/components/searchbox/SearchBox.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createRef } from 'preact';
import { useEffect, useState } from 'preact/hooks';
import { route } from 'preact-router';

import Show from '@/components/helpers/Show.tsx';
import SearchForm from '@/components/searchbox/SearchForm.tsx';
Expand Down Expand Up @@ -53,10 +54,13 @@ const SearchBox = (props) => {
setQuery('');
inputRef.current.blur();

// Get the active item based on the selected index
const selectedItem = results[selected]?.item;
if (selectedItem && props.onSelect) {
props.onSelect(selectedItem);
if (selected === -1) {
route(`/search/${encodeURIComponent(query)}`);
} else {
const selectedItem = results[selected]?.item;
if (selectedItem && props.onSelect) {
props.onSelect(selectedItem);
}
}

close();
Expand Down

0 comments on commit 1d2f72d

Please sign in to comment.