Skip to content

Commit

Permalink
feat: Allow to use arrow up/down to select
Browse files Browse the repository at this point in the history
  • Loading branch information
ptbrowne committed Sep 5, 2024
1 parent 1fc22ca commit a63ba91
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions website/src/pages/mutations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,22 @@ export default function Page() {
borderRight: "1px solid #ccc",
p: 1,
}}
onKeyDown={(ev) => {
if (!groupedMutations) {
return;
}
const index = highlightedMunicipalities
? groupedMutations.indexOf(highlightedMunicipalities)
: -1;
if (ev.key === "ArrowDown" && index < groupedMutations.length - 1) {
ev.preventDefault();
setHighlightedMunicipalities(groupedMutations[index + 1]);
}
if (ev.key === "ArrowUp" && index > 0) {
ev.preventDefault();
setHighlightedMunicipalities(groupedMutations[index - 1]);
}
}}
>
<Box sx={{ p: 1 }}>
<Box
Expand Down Expand Up @@ -153,12 +169,18 @@ export default function Page() {
</Box>
</Box>
{(groupedMutations ?? []).map((parsed, index) => {
const selected = highlightedMunicipalities === parsed;
return (
<ListItem
selected={highlightedMunicipalities === parsed}
selected={selected}
key={index}
button
onClick={() => handleMutationSelect(parsed)}
ref={
selected
? (node) => node?.scrollIntoView({ behavior: "smooth" })
: undefined
}
>
<ListItemText
primary={
Expand All @@ -171,7 +193,7 @@ export default function Page() {
</>
}
secondary={`${parsed.year}${
parsed.type ? `- ${parsed.type?.toLowerCase()}` : ""
parsed.type ? ` - ${parsed.type?.toLowerCase()}` : ""
}`}
/>
</ListItem>
Expand Down

0 comments on commit a63ba91

Please sign in to comment.