JakeGinnivan / react-popout

React popout is a React component wrapping window.open allowing you to host content in a browser popup window.
MIT License
188 stars 59 forks source link

Opening Multiple Popout Windows #45

Closed ahhughes closed 6 years ago

ahhughes commented 6 years ago

Disclaimer: I haven't found the time to see if I can reproduce this in the demo's...

I haven't found a way to open multiple pop-outs at once successfully. In my example, the second popout content is always empty. There appear to be some issues around registering event listeners also.

Should this be possible?

marchaos commented 6 years ago

Yes, we use this to open multiple windows in our environment. Do you have a code example?

ahhughes commented 6 years ago

Hi marchaos, thanks for replying. I earased my second popout and started from scratch and it's now working as desired. I can't explain why this did not work but breakpoint were being hit in sub components of the popout however they never went into the dom.

Something I did previously was supply popout sub components the redux store for connectors to work. I've changed this for the second window all sub complements properties are supplied from the popout (i.e. there are no deeper connectors than the pop out).

You're welcome to close this out, I'll amend the issue if I find something concrete.

Thanks a heap!

marchaos commented 6 years ago

Ok cool.

We use redux as well, but use a Provider so that you can access the store in connected components. We have a generic component that renders a list of PopoutWindow objects, using the children passed to that component as the children of the PopoutWindow. The render method of that "factory" looks something like this.

<PopoutWindow
       url={url}
       ...
       options={{ width: `${width}px`, height: `${height}px`, top: center.y, left: center.x }}
>
      {popoutWindow => <Provider store={store}>{React.cloneElement(children, { window: popoutWindow, ...window })}</Provider>}
</PopoutWindow>

Note that the child to PopoutWindow is a function as we need access to the actual browser popout window object.