Skip to content

Commit

Permalink
fix(Popover): Tippy bug on inputs getting height: 0
Browse files Browse the repository at this point in the history
  • Loading branch information
itsweliton committed Jun 14, 2021
1 parent a28fad9 commit fd2f569
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
33 changes: 33 additions & 0 deletions src/components/Popover/LazyTippy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/** @jsxImportSource theme-ui */
import { forwardRef, useState } from "react"
import Tippy, { TippyProps } from "@tippyjs/react"

const LazyTippy = forwardRef(function LazyTippy(props: TippyProps, ref) {
const [mounted, setMounted] = useState(false)

const lazyPlugin = {
fn: () => ({
onMount: () => setMounted(true),
onHidden: () => setMounted(false),
}),
}

const computedProps = { ...props }

computedProps.plugins = [lazyPlugin, ...(props.plugins || [])]

if (props.render) {
computedProps.render = (...arguments_) =>
mounted ? props.render(...arguments_) : ""
} else {
computedProps.content = mounted ? props.content : ""
}

return (
<Tippy {...computedProps} ref={ref}>
{props.children}
</Tippy>
)
})

export default LazyTippy
7 changes: 4 additions & 3 deletions src/components/Popover/Popover.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/** @jsxImportSource theme-ui */
import { ThemeUICSSObject } from "theme-ui"
import React, { useCallback, useRef, useState } from "react"
import Tippy, { TippyProps } from "@tippyjs/react"
import { TippyProps } from "@tippyjs/react"
import { roundArrow } from "tippy.js"
import ReactDOM from "react-dom"
import { ssrSafeCreateDiv } from "../../helpers/ssr"
import LazyTippy from "./LazyTippy"

export interface PopoverProps {
/** Popover content */
Expand Down Expand Up @@ -167,7 +168,7 @@ const Popover = ({

return (
<React.Fragment>
<Tippy
<LazyTippy
content={content}
theme={theme}
visible={isVisible}
Expand Down Expand Up @@ -233,7 +234,7 @@ const Popover = ({
}}
>
{children}
</Tippy>
</LazyTippy>
{hasBackgroundOverlay && overlayRef.current
? ReactDOM.createPortal(
<div
Expand Down

0 comments on commit fd2f569

Please sign in to comment.