Aria-Label not set by mapbox-gl [Bug]
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 8.5k
- Forks
- 1.4k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 3
Description
Description
When adding a [aria-label] attibute to the child element of a marker, this should be copied to the marker itself.
Based on the code of the underlying mapbox-gl-js library.:
https://github.com/mapbox/mapbox-gl-js/blob/1621f7f75597d56318f7ca12a9494f05a94cdabf/src/ui/marker.js#L166
but because of the creation of a new div element in this marker wrapper this feature isn't triggered.
https://github.com/visgl/react-map-gl/blob/109c334bdffaa5b2016c50bf6aaa119ce56082ce/src/components/marker.ts#L100
and we end-up with all markers that have the same [aria-label] = "Map marker"
Expected Behavior
aria-label of child element should be copied to the marker.
Steps to Reproduce
<Marker longitude={long} latitude={lat}><div aria-label="welcome home">home</div></Marker>
will end-up with a marker aria-label="Map marker" instead of "welcome home"
possible fix:
`
const marker = useMemo(() => {
let childElement = null;
React.Children.forEach(props.children, el => {
if (el) {
const { children, ...other } = el.props;
childElement = document.createElement('div');
if (other['aria-label']) {
childElement.setAttribute('aria-label', other['aria-label']);
}
}
});
const options = {
...props,
element: childElement
};
.....
`
Environment
- Framework version: react-map-gl@7.0.21
- Map library: mapbox-gl@2.12.0
- Browser: Chrome 109.0.5414.119
- OS: OSX ventura 13.1
Logs
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/components/marker.ts around line 100, where the marker wrapper creates a new div, and compare its behavior with the referenced mapbox-gl marker implementation. Reproduce the supplied Marker example with aria-label="welcome home"; done means the marker uses that label instead of the default "Map marker".
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- accessibility, frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100