diff --git a/frontend/web/components/Tooltip.tsx b/frontend/web/components/Tooltip.tsx index 5404a91b1b89..e36f3c059bf8 100644 --- a/frontend/web/components/Tooltip.tsx +++ b/frontend/web/components/Tooltip.tsx @@ -3,6 +3,7 @@ import ReactTooltip, { TooltipProps as _TooltipProps } from 'react-tooltip' import Utils from 'common/utils/utils' import classNames from 'classnames' import { sanitize } from 'dompurify' +import { createPortal } from 'react-dom' export type TooltipProps = { title: ReactNode @@ -13,6 +14,18 @@ export type TooltipProps = { tooltipClassName?: string effect?: _TooltipProps['effect'] afterShow?: _TooltipProps['afterShow'] + renderInPortal?: boolean // Controls backwards compatibility for rendering in portal +} + +const TooltipPortal: FC<{ children: ReactNode; renderInPortal?: boolean }> = ({ + children, + renderInPortal = false, +}) => { + const domNode = document.createElement('div') + document.body.appendChild(domNode) + + if (!renderInPortal) return <>{children} + return domNode ? createPortal(children, domNode) : null } const Tooltip: FC = ({ @@ -21,6 +34,7 @@ const Tooltip: FC = ({ effect, place, plainText, + renderInPortal, title, titleClassName, tooltipClassName, @@ -39,22 +53,24 @@ const Tooltip: FC = ({ )} {!!children && ( - - {plainText ? ( - `${children}` - ) : ( -
- )} - + + + {plainText ? ( + `${children}` + ) : ( +
+ )} + + )} )