Skip to content

Commit

Permalink
fix Popover controlled mode during first render (#1276)
Browse files Browse the repository at this point in the history
  • Loading branch information
mayank99 authored May 15, 2023
1 parent 6b714e1 commit 5cfd0bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/poor-bees-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@itwin/itwinui-react': patch
---

Fixed an issue where using Popover components in controlled mode (through `visible` prop) was appending it to the wrong root element.
7 changes: 6 additions & 1 deletion packages/itwinui-react/src/core/utils/components/Popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import cx from 'classnames';
import Tippy from '@tippyjs/react';
import type { TippyProps } from '@tippyjs/react';
import type { Placement, Instance } from 'tippy.js';
import { useMergedRefs } from '../hooks/useMergedRefs.js';
import { useMergedRefs, useIsClient } from '../hooks/index.js';
export type PopoverInstance = Instance;
import '@itwin/itwinui-css/css/utils.css';
import { ThemeContext } from '../../ThemeProvider/ThemeProvider.js';
Expand Down Expand Up @@ -40,6 +40,7 @@ export type PopoverProps = {
export const Popover = React.forwardRef((props: PopoverProps, ref) => {
const [mounted, setMounted] = React.useState(false);
const themeInfo = React.useContext(ThemeContext);
const isDomAvailable = useIsClient();

const tippyRef = React.useRef<Element>(null);
const refs = useMergedRefs(tippyRef, ref);
Expand Down Expand Up @@ -74,6 +75,10 @@ export const Popover = React.forwardRef((props: PopoverProps, ref) => {
zIndex: 99999,
...props,
className: cx('iui-popover', props.className),
// add additional check for isDomAvailable when using in controlled mode,
// because rootRef is not available in first render
visible:
props.visible !== undefined ? props.visible && isDomAvailable : undefined,
plugins: [
lazyLoad,
removeTabIndex,
Expand Down

0 comments on commit 5cfd0bb

Please sign in to comment.