fix: enter click no redirect with onselect

This commit is contained in:
TrèsAbhi committed 2024-06-28 20:17:47 -05:00
1 parent 0558f27347
commit abac64f01b
2 files changed
+9 -3

No files matched your search

@@ -10,9 +10,10 @@ import { Sort } from './Sort';
interface SearchBarProps {
topResult?: TankDefinition;
onSelect?: (tank: TankDefinition) => void;
}
export function SearchBar({ topResult }: SearchBarProps) {
export function SearchBar({ topResult, onSelect }: SearchBarProps) {
const router = useRouter();
const input = useRef<HTMLInputElement>(null);
const searching = useTankopediaFilters((state) => state.searching);
@@ -42,7 +43,12 @@ export function SearchBar({ topResult }: SearchBarProps) {
if (event.key !== 'Enter' || !topResult || searching) return;
event.preventDefault();
router.push(`/tools/tankopedia/${topResult.id}`);
if (onSelect) {
onSelect(topResult);
} else {
router.push(`/tools/tankopedia/${topResult.id}`);
}
},
[topResult],
);
@@ -360,7 +360,7 @@ export const TankSearch = memo<TankSearchProps>(
return (
<Flex direction="column" gap="4" flexGrow="1" {...props}>
<SearchBar topResult={tanks?.[0]} />
<SearchBar topResult={tanks?.[0]} onSelect={onSelect} />
{!filters.search && !filters.searching && (
<FilterControl compact={compact} />