Skip to content

Commit d1712dc

Browse files
authored
Merge pull request #5713 from dfe-analytical-services/EES-5910-tab-through-maps-tooltips-visibility
EES-5910 Ensure tooltips visible when tabbing through map regions
2 parents 1db8df2 + 1ced806 commit d1712dc

File tree

1 file changed

+17
-2
lines changed
  • src/explore-education-statistics-common/src/modules/charts/components

1 file changed

+17
-2
lines changed

src/explore-education-statistics-common/src/modules/charts/components/MapGeoJSON.tsx

+17-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ export default function MapGeoJSON({
8888

8989
useEffect(() => {
9090
if (!selectedFeature) {
91-
// reset zoom
92-
map.setZoom(5);
91+
resetZoom();
9392
return;
9493
}
9594

@@ -107,6 +106,8 @@ export default function MapGeoJSON({
107106
}
108107
}, [map, selectedFeature]);
109108

109+
const resetZoom = () => map.setZoom(5);
110+
110111
// We have to assign our `onEachFeature` callback to a ref
111112
// as `onEachFeature` forms an internal closure which
112113
// prevents us from updating the callback's dependencies.
@@ -206,6 +207,20 @@ export default function MapGeoJSON({
206207
onSelectFeature(feature);
207208
}
208209
},
210+
keydown: e => {
211+
if (e.originalEvent.code === 'Tab') {
212+
// https://dfedigital.atlassian.net/browse/EES-5910
213+
// Reset the map zoom when user tabs through regions
214+
// to ensure tooltips that appear are in bounds and visible
215+
resetZoom();
216+
} else if (e.originalEvent.code === 'Enter') {
217+
// Also allow a feature to be 'selected' by pressing Enter
218+
const { feature } = e.sourceTarget;
219+
if (feature.properties && feature.id) {
220+
onSelectFeature(feature);
221+
}
222+
}
223+
},
209224
}}
210225
/>
211226
)}

0 commit comments

Comments
 (0)