michaelmuxica michaelmuxica - 1 month ago 27x
Javascript Question

How to replace React-Leaflet Popup with custom component?

I'm using React-Leaflet and (callemall)Material-UI in a project. I'm attempting to render the Material-UI Card component within the

component of React-Leaflet. I've tried pulling it into the Popup as a component but the popup doesn't let the component work as it should. Specifically, the card component has a button element that expands it but unfortunately, the popup won't let me click it. I'm sure there's some CSS-y thing that I need to override but my thought is that an easier option would be to just replace the popup component with my own component but I'm not sure how to go about doing so. Any insight is much appreciated :)

My code looks like this:

<Marker position={position}>
<MapPopup />

And the imported component looks like: (I've removed styles and unimportant details to make it simple to read)

<CardHeader />
<CardText expandable={true}>
<img src="cardMediaImageURL" />


Long story short, React-Leaflet and Leaflet renders static html for the popup so it is not possible to render dynamic content within it. Rendering a material-ui component is possible, however it won't be interactive. You can accomplish this by wrapping your component with <MuiThemeProvider></MuiThemeProvider>. You just have to make sure that you have the content set to be the complete view and not with anything like an expander.

Solution is as follows:

<Popup> <MuiThemeProvider muiTheme={getMuiTheme(yourThemeName)}> <YourCustomComponent /> </MuiThemeProvider>