Skip to content

Commit

Permalink
Allow switching between routing alternatives using arrow keys
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmurray committed Nov 21, 2023
1 parent e3f8336 commit 9993d74
Showing 1 changed file with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,34 @@ const RoutingResults: React.FunctionComponent<TransitRoutingResultsProps> = (pro
// TODO This may be racy (it already was) if the user switches alternative rapidly. Make it cancellable.
showCurrentAlternative(result, alternativeIndex);

const onLeftButtonClick = () => {
setAlternativeIndex(alternativeIndex > 0 ? alternativeIndex - 1 : alternativesCount - 1)
};

const onRightButtonClick = () => {
setAlternativeIndex(alternativesCount > alternativeIndex + 1 ? alternativeIndex + 1 : 0)
};

return (
<React.Fragment>
<div>
<div className="tr__form-buttons-container">
<div
className="tr__form-buttons-container"
onKeyDown={(e) => {
if (e.key === 'ArrowLeft') {
onLeftButtonClick();
} else if (e.key === 'ArrowRight') {
onRightButtonClick();
}
}}
>
{alternativesCount > 1 && (
<Button
icon={faAngleLeft}
color="blue"
iconClass="_icon-alone"
label=""
onClick={() =>
setAlternativeIndex(alternativeIndex > 0 ? alternativeIndex - 1 : alternativesCount - 1)
}
onClick={onLeftButtonClick}
/>
)}
{alternativesCount > 0 && (
Expand All @@ -90,9 +105,7 @@ const RoutingResults: React.FunctionComponent<TransitRoutingResultsProps> = (pro
color="blue"
iconClass="_icon-alone"
label=""
onClick={() =>
setAlternativeIndex(alternativesCount > alternativeIndex + 1 ? alternativeIndex + 1 : 0)
}
onClick={onRightButtonClick}
/>
)}
</div>
Expand Down

0 comments on commit 9993d74

Please sign in to comment.