feat: enter to select first tank

This commit is contained in:
TrèsAbhi committed 2024-04-06 22:00:40 -05:00
1 parent 6d48f9fe7f
commit 2e0d52e30e
1 file changed
+25
@@ -1,6 +1,7 @@
import { slateDark } from '@radix-ui/colors';
import {
CaretDownIcon,
CaretRightIcon,
MagnifyingGlassIcon,
TrashIcon,
} from '@radix-ui/react-icons';
@@ -445,10 +446,34 @@ export function TankSearch({
setSearchedList(results);
}}
onKeyDown={(event) => {
if (event.key === 'Enter') {
if (
searchResults.length > 0 &&
input.current &&
input.current.value.length > 0
) {
onSelect(searchResults[0]);
}
}
}}
>
<TextField.Slot>
<MagnifyingGlassIcon height="16" width="16" />
</TextField.Slot>
{searchResults.length > 0 &&
input.current &&
input.current.value.length > 0 && (
<TextField.Slot>
<Button
variant="ghost"
onClick={() => onSelect(searchResults[0])}
>
{searchResults[0].name} <CaretRightIcon />
</Button>
</TextField.Slot>
)}
</TextField.Root>
<DropdownMenu.Root>