Skip to content

Commit

Permalink
Merge pull request #15 from collective/fix_accessibilità_marker_mappa
Browse files Browse the repository at this point in the history
feat: added aria tags for SR accessibility
  • Loading branch information
sabrina-bongiovanni committed Oct 11, 2023
2 parents f80da13 + 9244f44 commit e999e76
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions src/components/OSMMap/OSMMap.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { defineMessages } from 'react-intl';
import { defineMessages, useIntl } from 'react-intl';
import PropTypes from 'prop-types';
import L from 'leaflet';
import { Map, TileLayer, Marker, Tooltip, Popup } from 'react-leaflet';
Expand All @@ -15,12 +15,14 @@ import 'volto-venue/components/OSMMap/OSMMap.css';
// eslint-disable-next-line import/no-unresolved
import 'volto-venue/components/OSMMap/leaflet.css';

const messages = defineMessages({
attribution: {
id: '&amp;copy <a href="http://osm.org/copyright">OpenStreetMap</a> contributors',
defaultMessage: '&amp;copy <a href="http://osm.org/copyright">OpenStreetMap</a> contributors',
},
});
// const messages = defineMessages({
// attribution: {
// id:
// '&amp;copy <a href="http://osm.org/copyright">OpenStreetMap</a> contributors',
// defaultMessage:
// '&amp;copy <a href="http://osm.org/copyright">OpenStreetMap</a> contributors',
// },
// });

let DefaultIcon = L.icon({
iconUrl: icon,
Expand All @@ -43,6 +45,7 @@ const OSMMap = ({
cluster = false,
mapOptions = {},
}) => {
// const intl = useIntl();
const bounds = L.latLngBounds(
markers.map((marker) => [marker.latitude, marker.longitude]),
);
Expand All @@ -56,15 +59,30 @@ const OSMMap = ({
draggable={draggable}
onDragend={onMarkerDragEnd}
onClick={position.onMarkerClick}
onKeyDown={(event) => {
if (event.originalEvent.key === 'Enter') {
position.onMarkerClick();
}
}}
icon={position.divIcon ? L.divIcon(position.divIcon) : DefaultIcon}
aria-label={position.title}
title={position.title}
>
{showTooltip && position.title && (
<Tooltip offset={[0, -22]} direction="top">
<Tooltip
offset={[0, -22]}
direction="top"
aria-label={position.title}
>
{position.title}
</Tooltip>
)}
{showPopup && position.popupContent && (
<Popup offset={[0, -22]} direction="top">
<Popup
offset={[0, -22]}
direction="top"
aria-label={position.title}
>
{position.popupContent}
</Popup>
)}
Expand All @@ -83,7 +101,7 @@ const OSMMap = ({
{...mapOptions}
>
<TileLayer
attribution={intl.formatMessage(messages.attribution)}
// attribution={intl.formatMessage(messages.attribution)}
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
{cluster ? (
Expand Down

0 comments on commit e999e76

Please sign in to comment.