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

Rendering into portals? #268

Closed
oyeanuj opened this issue Mar 2, 2017 · 2 comments
Closed

Rendering into portals? #268

oyeanuj opened this issue Mar 2, 2017 · 2 comments
Labels

Comments

@oyeanuj
Copy link
Contributor

oyeanuj commented Mar 2, 2017

Hi @wwayne, is it possible to render the tooltip into a portal (or just to the body element) other than just declaring it at the very top level?

In my case, I use tooltips at a lot of places in the code, but running into special use-cases when using it in elements within contenteditable editors. To make it not editable, ideally I want to render it outside the editable, but then be able to render different tooltip body based on what is being hovered upon within the editable.

Ideally, rendering into a portal would be ideal for such a use-case.

Thoughts?

Thank you!

@oyeanuj
Copy link
Contributor Author

oyeanuj commented Apr 18, 2017

@wwayne @huumanoid Any thoughts on this?

@madrussa
Copy link

It's very simple to create a portal wrapper component to achieve this functionality. I wouldn't see the need to implement this in the react-tooltip library as most people will need fine grain control.

Below is a naive example of how I render react-tooltip into portals. This works fine and the tooltips continue to position correctly over different layered areas.

import React from "react";
import ReactDOM from "react-dom";
import ReactTooltip from "react-tooltip";

// Create root level element for react-tooltips
const domNode = document.createElement('div');
document.body.appendChild(domNode);

// Wrapper component to portal react-tooltips
function BodyPortal ({ children }) {
  return ReactDOM.createPortal(
    children,
    domNode
  );
}

// Custom tooltip wrapper to ensure all tooltips get rendered into the portal
function CustomReactTooltip (props) {
  return (
    <BodyPortal>
      <ReactTooltip
        type="light"
        effect="solid"
        {...props}
      />
    </BodyPortal>
  );
}

export default CustomReactTooltip;

Hopefully those experiencing issues with z-indexing and content editable regions will find this useful.

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

No branches or pull requests

4 participants