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

Feature request: Exposes Portal Context #428

Closed
lxcid opened this issue Sep 1, 2019 · 3 comments
Closed

Feature request: Exposes Portal Context #428

lxcid opened this issue Sep 1, 2019 · 3 comments

Comments

@lxcid
Copy link
Contributor

lxcid commented Sep 1, 2019

🚀 Feature request

Motivation

I was wondering what do you think about exposing the PortalContext so that we can control where portal should live in the DOM. This might be useful if I want to manage the root level DOM elements.

I'm not sure if hiding PortalContext is something you explicitly wanted and have a reason for. If so, could you share your thoughts?

Example

Using LayersManager (https://github.com/giuseppeg/react-layers-manager/blob/master/src/LayersManager.js) as an example:

export default class LayersManager extends React.Component {
  root = React.createRef()
  host = React.createRef()
  state = {
    root: this.root.current,
    host: this.host.current,
  }
  componentDidMount() {
    this.setState({
      root: this.root.current,
      host: this.host.current,
    })
  }
  render() {
    return (
      <PortalContext.Provider value={this.state.host}>
        <Provider value={this.state}>
          <div ref={this.root} style={{ opacity: 0.9999999 }}>
            {this.props.children}
          </div>
          <div ref={this.host} style={{ opacity: 0.9999999 }} />
        </Provider>
      </PortalContext.Provider>
    )
  }
}

Any portal created inside the children will be append as child of host. And nested portal will still function as designed.

Possible implementations

Just need to export PortalContext?

@open-collective-bot
Copy link

Hey @lxcid 👋,

Thank you so much for supporting us on Open Collective ❤️.
We'll give a special attention to this issue.

@diegohaz
Copy link
Member

diegohaz commented Sep 1, 2019

Hi @lxcid! Thanks for opening the issue!

I think the only reason for not exposing this was the lack of use cases. You're bringing one to light right now, so I think we should add that.

Would you like to do that?

@lxcid
Copy link
Contributor Author

lxcid commented Sep 2, 2019

Thanks Haz! I see, I’m not sure yet about my use case, but I believe some people might be concern about where their portal get created inthe DOM tree. If you have no objection I can send a small PR once I get home.

btw, I love your portal implementation. I’ve been looking around and I think yours is the best one. 👍

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

No branches or pull requests

2 participants