Commit 1bbe48e9 by Johannes Schill

Create a portal and use it with our popper component (tooltip and popover) to…

Create a portal and use it with our popper component (tooltip and popover) to avoid potential overflow-/zindex-bugs
parent 0a8f23d8
import { PureComponent } from 'react';
import ReactDOM from 'react-dom';
interface Props {
className?: string;
}
export default class BodyPortal extends PureComponent<Props> {
node: HTMLElement = document.createElement('div');
portalRoot = document.body;
constructor(props) {
super(props);
const { className } = this.props;
if (className) {
this.node.classList.add();
}
this.portalRoot.appendChild(this.node);
}
componentWillUnmount() {
this.portalRoot.removeChild(this.node);
}
render() {
return ReactDOM.createPortal(this.props.children, this.node);
}
}
import React, { PureComponent } from 'react';
import BodyPortal from 'app/core/components/Portal/BodyPortal';
import { Manager, Popper as ReactPopper, Reference } from 'react-popper';
import Transition from 'react-transition-group/Transition';
......@@ -38,27 +39,29 @@ class Popper extends PureComponent<Props> {
</Reference>
<Transition in={show} timeout={100} mountOnEnter={true} unmountOnExit={true}>
{transitionState => (
<ReactPopper placement={placement}>
{({ ref, style, placement, arrowProps }) => {
return (
<div
ref={ref}
style={{
...style,
...defaultTransitionStyles,
...transitionStyles[transitionState],
}}
data-placement={placement}
className="popper"
>
<div className="popper__background">
{renderContent(content)}
<div ref={arrowProps.ref} data-placement={placement} className="popper__arrow" />
<BodyPortal className="hej">
<ReactPopper placement={placement}>
{({ ref, style, placement, arrowProps }) => {
return (
<div
ref={ref}
style={{
...style,
...defaultTransitionStyles,
...transitionStyles[transitionState],
}}
data-placement={placement}
className="popper"
>
<div className="popper__background">
{renderContent(content)}
<div ref={arrowProps.ref} data-placement={placement} className="popper__arrow" />
</div>
</div>
</div>
);
}}
</ReactPopper>
);
}}
</ReactPopper>
</BodyPortal>
)}
</Transition>
</Manager>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment