visgl / visgl/react-map-gl

Aria-Label not set by mapbox-gl [Bug]

Open
#2,115 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.