Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

window prop not working as specified in the doc #29

Closed
tgroutars opened this issue Jan 17, 2017 · 2 comments
Closed

window prop not working as specified in the doc #29

tgroutars opened this issue Jan 17, 2017 · 2 comments

Comments

@tgroutars
Copy link

Hi @JakeGinnivan ,
First, thanks for your work on react-popout :)

I'm using it in a project and I need to access the window that was opened in my parent component.

To do that, I tried to use the window prop. In the README, you say it need to be an object with a open method on it. So I just did that, I pass an object like this:

{
  open: (...args) => {
    const popoutWindow = window.open(...args);
    this.setState({ popoutWindow });
    return popoutWindow;
  }
}

However, I get an error that (this.props.window || window).removeEventListener is not a function

So my fake window actually might need a few other methods to work properly. I was wondering if you had a comprehensive list of the methods I should implement, so that I'm sure that it won't break?

Another solution to my problem would be to have a callback prop that would be called once the window is opened, passing the window object in argument, like so:

  onPopoutOpened: function(popoutWindow) {
    this.setState({ popoutWindow });
  },

...

  render: function() {
    return <Popout onPopoutOpened={this.onPopoutOpened} />;
  }

Any intention to do that in the future? Tell me if you'd like a PR for this.

@marchaos
Copy link
Collaborator

I have added this functionality in my branch of this project. See https://github.com/marchaos/react-popout.

To get access to the window, use a function for children like so:

<PopoutWindow {...}>
    {popoutWindow => (
            <MyComponent popoutWindow={popoutWindow} />
    )}
</PopoutWindow>

popoutWindow will be a reference to the window returned internally by window.open.

@marchaos
Copy link
Collaborator

Closing this as the above functionality has been merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants