Skip to content

Commit

Permalink
Add a possibility for ArrowButton comp to handle keyboard events
Browse files Browse the repository at this point in the history
It was already able to handle click events, but not keyboard events,
which made it inaccessible.
  • Loading branch information
Adamik10 committed Jan 15, 2024
1 parent 08c6392 commit 2b3e4fe
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/components/Buttons/ArrowButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import Arrow from "../atoms/icons/arrow/arrow";
export interface ArrowButtonProps {
cursorPointer: boolean;
clickEventHandler?: () => void;
keyUpEventHandler?: (e: React.KeyboardEvent<HTMLButtonElement>) => void;
arrowLabelledBy: string;
}

const ArrowButton: React.FC<ArrowButtonProps> = ({
cursorPointer = false,
clickEventHandler,
keyUpEventHandler,
arrowLabelledBy
}) => {
const pointer = (cursorPointer && { cursor: "pointer" }) || {
Expand All @@ -27,6 +29,12 @@ const ArrowButton: React.FC<ArrowButtonProps> = ({
clickEventHandler();
}
}}
onKeyUp={(e) => {
if (keyUpEventHandler) {
e.stopPropagation();
keyUpEventHandler(e);
}
}}
>
<Arrow />
</button>
Expand Down

0 comments on commit 2b3e4fe

Please sign in to comment.