Skip to content
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