feat: a little bit of keyboard nav

This commit is contained in:
TrèsAbhi committed 2023-10-01 16:16:32 -05:00
1 parent 4d1dfc1ae5
commit 7bb3c60a61
1 file changed
+21 -13
+21 -13
View File
@@ -89,7 +89,13 @@ export default function Page() {
}} }}
onBlur={(event) => { onBlur={(event) => {
// TODO: remove this hack when https://github.com/radix-ui/primitives/issues/2193 is fixed // TODO: remove this hack when https://github.com/radix-ui/primitives/issues/2193 is fixed
event.target.value.length === 1 && event.target.focus(); showSearchResults && event.target.focus();
}}
onKeyDown={(event) => {
if (event.key === 'Escape') {
setShowSearchResults(false);
input.current?.blur();
}
}} }}
placeholder="Search for a player..." placeholder="Search for a player..."
/> />
@@ -106,18 +112,20 @@ export default function Page() {
) : searchResults.length === 0 ? ( ) : searchResults.length === 0 ? (
<DropdownMenu.Item disabled>No results</DropdownMenu.Item> <DropdownMenu.Item disabled>No results</DropdownMenu.Item>
) : ( ) : (
searchResults?.map(({ account_id: id, nickname, region }) => ( searchResults?.map(
<DropdownMenu.Item ({ account_id: id, nickname, region }, index) => (
key={id} <DropdownMenu.Item
onClick={() => { key={id}
setShowSearchResults(false); onClick={() => {
setSession(region, id, nickname); setShowSearchResults(false);
}} setSession(region, id, nickname);
shortcut={REGION_NAMES[region]} }}
> shortcut={REGION_NAMES[region]}
{nickname} >
</DropdownMenu.Item> {nickname}
)) </DropdownMenu.Item>
),
)
)} )}
</DropdownMenu.Content> </DropdownMenu.Content>
</DropdownMenu.Root> </DropdownMenu.Root>