Skip to content

Commit 5b2e063

Browse files
committed
feat: aria labels for pins
1 parent 964e5cd commit 5b2e063

2 files changed

Lines changed: 36 additions & 5 deletions

File tree

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,37 @@
1+
import { AllPossiblePapersType } from "@/js/types";
12
import L from "leaflet";
23

3-
export const createPinIcon = (isActive: boolean) =>
4-
L.divIcon({
4+
const getAriaLabel = (data: AllPossiblePapersType): string => {
5+
let result = "";
6+
7+
if (!("geographicalData" in data)) {
8+
return result;
9+
}
10+
11+
const { title, geographicalData } = data;
12+
13+
if (title) {
14+
result = title;
15+
}
16+
17+
if (geographicalData) {
18+
const { continent, country } = geographicalData;
19+
result = result + `; ${country}, ${continent}`;
20+
}
21+
22+
return result;
23+
};
24+
25+
export const createPinIcon = (
26+
isActive: boolean,
27+
data: AllPossiblePapersType,
28+
) => {
29+
const ariaLabel = getAriaLabel(data);
30+
31+
return L.divIcon({
532
className: `custom-marker ${isActive ? "selected" : ""}`,
6-
html: `<div class="marker-shape"></div>`,
33+
html: `<div class="marker-shape" role="button" aria-label="${ariaLabel}"></div>`,
734
iconSize: [22, 30],
835
iconAnchor: [11, 30],
936
});
37+
};

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@ import { Marker } from "react-leaflet";
44
import { getCoordinatesFromPaper } from "@/js/utils/coordinates";
55

66
import { CONFIG } from "./config";
7-
import { createPinIcon } from "./createPinIcon";
7+
88
import { PinProps } from "./types";
9+
import { createPinIcon } from "./createPinIcon";
910

1011
const { offsets } = CONFIG;
1112
const { basic, selected } = offsets;
1213

1314
export const Pin: FC<PinProps> = memo(({ data, isActive, onClick }) => {
1415
const { east, north } = getCoordinatesFromPaper(data);
1516

17+
console.log("Pin rendering");
18+
1619
const handleClick = () => onClick(data);
1720

1821
if (!east || !north) {
@@ -22,7 +25,7 @@ export const Pin: FC<PinProps> = memo(({ data, isActive, onClick }) => {
2225
return (
2326
<Marker
2427
position={[north, east]}
25-
icon={createPinIcon(isActive)}
28+
icon={createPinIcon(isActive, data)}
2629
zIndexOffset={isActive ? selected : basic}
2730
eventHandlers={{
2831
click: handleClick,

0 commit comments

Comments
 (0)