Skip to content

Commit 8638f8f

Browse files
committed
feat: pin selection using keyboard
1 parent 90b80a5 commit 8638f8f

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

vis/js/templates/Geomap/Pins/Pin/index.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
import L from "leaflet";
12
import { FC, memo } from "react";
23
import { Marker } from "react-leaflet";
34

45
import { getCoordinatesFromPaper } from "@/js/utils/coordinates";
56

67
import { CONFIG } from "./config";
7-
8-
import { PinProps } from "./types";
98
import { createPinIcon } from "./createPinIcon";
9+
import { PinProps } from "./types";
1010

1111
const { offsets } = CONFIG;
1212
const { basic, selected } = offsets;
@@ -16,6 +16,15 @@ export const Pin: FC<PinProps> = memo(({ data, isActive, onClick }) => {
1616

1717
const handleClick = () => onClick(data);
1818

19+
const handleKeydown = (event: L.LeafletKeyboardEvent) => {
20+
const key = event.originalEvent.key;
21+
22+
if (key === "Enter" || key === " ") {
23+
event.originalEvent.preventDefault();
24+
handleClick();
25+
}
26+
};
27+
1928
if (!east || !north) {
2029
return null;
2130
}
@@ -24,9 +33,11 @@ export const Pin: FC<PinProps> = memo(({ data, isActive, onClick }) => {
2433
<Marker
2534
position={[north, east]}
2635
icon={createPinIcon(isActive, data)}
36+
keyboard
2737
zIndexOffset={isActive ? selected : basic}
2838
eventHandlers={{
2939
click: handleClick,
40+
keydown: handleKeydown,
3041
}}
3142
/>
3243
);

0 commit comments

Comments
 (0)