Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aria-Label not set by mapbox-gl (#2115) #2159

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/components/marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,26 @@ function Marker(props: MarkerProps) {

const marker: MapboxMarker = useMemo(() => {
let hasChildren = false;
let childElement = null;

React.Children.forEach(props.children, el => {
if (el) {
hasChildren = true;

const element = el as JSX.Element;
const {children, ...other} = element.props;

childElement = document.createElement('div');

if (other['aria-label']) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be a strange way to handle aria label (what if multiple child elements have it defined?)... Is it easier to just add a new prop to the Maker component itself?

childElement.setAttribute('aria-label', other['aria-label']);
}
}
});

const options = {
...props,
element: hasChildren ? document.createElement('div') : null
element: childElement
};

const mk = new mapLib.Marker(options).setLngLat([props.longitude, props.latitude]);
Expand Down