react-map-interaction
react-map-interaction copied to clipboard
Use provided browsing context
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.