react-map-interaction icon indicating copy to clipboard operation
react-map-interaction copied to clipboard

Use provided browsing context

Open martin-pettersson opened this issue 1 year ago • 0 comments

I ran into a scenario where I needed to use this library in a popup window and the easiest solution was to render the component using a React portal. The issue then was that this library was listening for events on the "origin" window object instead of the popup window.

If we allow users to pass in a custom browsing context as a prop it's fairly easy to solve this issue. Here's a trivial example with some sudo-ish code to illustrate the solution.

const browsingContext = window.open("", "", "popup");

return createPortal(
    <MapInteractionCSS browsingContext={browsingContext} ...>
        ...
    </MapInteractionCSS>,
    browsingContext.document.body
);

Since we fall back to the global window object if no browsing context is provided this won't break anything.

martin-pettersson avatar Feb 14 '24 01:02 martin-pettersson