-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Popover): Tippy bug on inputs getting height: 0
- Loading branch information
1 parent
a28fad9
commit fd2f569
Showing
2 changed files
with
37 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters