mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-22 03:07:04 +02:00
fix: enter click no redirect with onselect
This commit is contained in:
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} />
|
||||
|
||||
Reference in new issue
Block a user