diff --git a/website/src/pages/mutations.tsx b/website/src/pages/mutations.tsx index a5c99c1..cdd5987 100644 --- a/website/src/pages/mutations.tsx +++ b/website/src/pages/mutations.tsx @@ -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]); + } + }} > {(groupedMutations ?? []).map((parsed, index) => { + const selected = highlightedMunicipalities === parsed; return ( handleMutationSelect(parsed)} + ref={ + selected + ? (node) => node?.scrollIntoView({ behavior: "smooth" }) + : undefined + } > } secondary={`${parsed.year}${ - parsed.type ? `- ${parsed.type?.toLowerCase()}` : "" + parsed.type ? ` - ${parsed.type?.toLowerCase()}` : "" }`} />