mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 03:59:50 +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 {
|
interface SearchBarProps {
|
||||||
topResult?: TankDefinition;
|
topResult?: TankDefinition;
|
||||||
|
onSelect?: (tank: TankDefinition) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function SearchBar({ topResult }: SearchBarProps) {
|
export function SearchBar({ topResult, onSelect }: SearchBarProps) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const input = useRef<HTMLInputElement>(null);
|
const input = useRef<HTMLInputElement>(null);
|
||||||
const searching = useTankopediaFilters((state) => state.searching);
|
const searching = useTankopediaFilters((state) => state.searching);
|
||||||
@@ -42,7 +43,12 @@ export function SearchBar({ topResult }: SearchBarProps) {
|
|||||||
if (event.key !== 'Enter' || !topResult || searching) return;
|
if (event.key !== 'Enter' || !topResult || searching) return;
|
||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
router.push(`/tools/tankopedia/${topResult.id}`);
|
|
||||||
|
if (onSelect) {
|
||||||
|
onSelect(topResult);
|
||||||
|
} else {
|
||||||
|
router.push(`/tools/tankopedia/${topResult.id}`);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[topResult],
|
[topResult],
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -360,7 +360,7 @@ export const TankSearch = memo<TankSearchProps>(
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex direction="column" gap="4" flexGrow="1" {...props}>
|
<Flex direction="column" gap="4" flexGrow="1" {...props}>
|
||||||
<SearchBar topResult={tanks?.[0]} />
|
<SearchBar topResult={tanks?.[0]} onSelect={onSelect} />
|
||||||
|
|
||||||
{!filters.search && !filters.searching && (
|
{!filters.search && !filters.searching && (
|
||||||
<FilterControl compact={compact} />
|
<FilterControl compact={compact} />
|
||||||
|
|||||||
Reference in new issue
Block a user