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
+11 -3
+11 -3
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,7 +112,8 @@ 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(
({ account_id: id, nickname, region }, index) => (
<DropdownMenu.Item <DropdownMenu.Item
key={id} key={id}
onClick={() => { onClick={() => {
@@ -117,7 +124,8 @@ export default function Page() {
> >
{nickname} {nickname}
</DropdownMenu.Item> </DropdownMenu.Item>
)) ),
)
)} )}
</DropdownMenu.Content> </DropdownMenu.Content>
</DropdownMenu.Root> </DropdownMenu.Root>