Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dropdown floating portals #860

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changeset/tidy-suits-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@igloo-ui/area-chart": patch
"@igloo-ui/dropdown": patch
"@igloo-ui/popover": patch
"@igloo-ui/select": patch
"@igloo-ui/text-editor": patch
"@igloo-ui/tooltip": patch
---

- Updated @floating-ui/react to latest to fix issues with FloatingPortal
- Updated Dropdown, Popover, FloatingLinkEditorPlugin, and Tooltip to render portals only when open
2 changes: 1 addition & 1 deletion packages/Dropdown/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"build": "rollup -c rollup.config.js"
},
"dependencies": {
"@floating-ui/react": "^0.26.22",
"@floating-ui/react": "^0.27.3",
"@hopper-ui/tokens": "^4.3.0",
"@igloo-ui/tokens": "^2.1.0",
"classnames": "^2.5.1"
Expand Down
40 changes: 26 additions & 14 deletions packages/Dropdown/src/Dropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import * as React from "react";
import cx from "classnames";
import {
autoUpdate,
flip,
FloatingFocusManager,
FloatingPortal,
size as fuiSize,
useMergeRefs,
offset,
hide,
autoUpdate,
useFloating,
FloatingFocusManager,
offset,
useDismiss,
useFloating,
useInteractions,
useTransitionStyles,
useMergeRefs,
useRole,
FloatingPortal
useTransitionStyles
} from "@floating-ui/react";
import cx from "classnames";
import * as React from "react";

import "./dropdown.scss";

Expand Down Expand Up @@ -239,6 +239,22 @@ const Dropdown: React.FunctionComponent<DropdownProps> = React.forwardRef(
}
}, [isMounted, onAfterClose, dropdownPreviouslyOpen]);

const renderFloatingElem = (): React.ReactNode => {
if (disablePortal) {
return floatingElem;
}

if (isMounted) {
return (
<FloatingPortal>
{floatingElem}
</FloatingPortal>
);
}

return null;
};

return (
<>
{renderReference ? (
Expand All @@ -252,11 +268,7 @@ const Dropdown: React.FunctionComponent<DropdownProps> = React.forwardRef(
{children}
</div>
)}
{disablePortal ? (
floatingElem
) : (
<FloatingPortal>{floatingElem}</FloatingPortal>
)}
{renderFloatingElem()}
</>
);
}
Expand Down
11 changes: 10 additions & 1 deletion packages/Dropdown/src/__snapshots__/Dropdown.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ exports[`Dropdown It should render without error and a snapshot 1`] = `
aria-expanded="true"
aria-haspopup="listbox"
class="ids-dropdown__ref"
data-floating-ui-inert=""
role="combobox"
>
<button>
Settings
</button>
</div>
<span
aria-hidden="true"
data-floating-ui-inert=""
style="border: 0px; height: 1px; margin: -1px; overflow: hidden; padding: 0px; position: fixed; white-space: nowrap; width: 1px; top: 0px; left: 0px;"
tabindex="-1"
/>
<span
data-floating-ui-focus-guard=""
data-type="outside"
Expand All @@ -23,6 +30,7 @@ exports[`Dropdown It should render without error and a snapshot 1`] = `
/>
<span
aria-owns=":r2:"
data-floating-ui-inert=""
style="border: 0px; height: 1px; margin: -1px; overflow: hidden; padding: 0px; position: fixed; white-space: nowrap; width: 1px; top: 0px; left: 0px;"
/>
<span
Expand All @@ -46,12 +54,13 @@ exports[`Dropdown It should render without error and a snapshot 1`] = `
/>
<div
class="ids-dropdown ids-dropdown--bottom-start"
data-floating-ui-focusable=""
data-show="true"
data-test="dropdown1"
id=":r0:"
role="listbox"
style="position: fixed; top: 0px; left: 0px; opacity: 0; transform: translateY(1rem);"
tabindex="0"
tabindex="-1"
>
<div
class="ids-dropdown__scroll-content"
Expand Down
2 changes: 1 addition & 1 deletion packages/Popover/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@igloo-ui/tokens": "^2.1.0",
"@hopper-ui/tokens": "^4.3.2",
"classnames": "^2.3.2",
"@floating-ui/react": "^0.26.9"
"@floating-ui/react": "^0.27.3"
},
"browserslist": [
"> 1%",
Expand Down
35 changes: 17 additions & 18 deletions packages/Popover/src/Popover.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import * as React from "react";
import cx from "classnames";
import {
autoPlacement,
autoUpdate,
flip,
shift,
FloatingFocusManager,
FloatingPortal,
offset,
autoUpdate,
useFloating,
safePolygon,
shift,
useClick,
useDismiss,
useFloating,
useHover,
useInteractions,
useTransitionStyles,
autoPlacement,
useRole,
FloatingPortal,
useClick,
useHover,
FloatingFocusManager,
safePolygon,
type ReferenceType,
useTransitionStyles,
type UseHoverProps
} from "@floating-ui/react";
import cx from "classnames";
import * as React from "react";

import IconButton from "@igloo-ui/icon-button";
import Close from "@igloo-ui/icons/dist/Close";
Expand Down Expand Up @@ -117,7 +116,7 @@ const Popover: React.FunctionComponent<PopoverProps> = ({
...floatingUIPlacement
});

const useHoverProps: UseHoverProps<ReferenceType> = {
const useHoverProps: UseHoverProps = {
enabled: triggerEvent === "hover",
restMs: 150
};
Expand Down Expand Up @@ -211,17 +210,17 @@ const Popover: React.FunctionComponent<PopoverProps> = ({
>
{children}
</span>
<FloatingPortal>
{isMounted && (
{isMounted && (
<FloatingPortal>
<FloatingFocusManager
context={context}
modal={false}
initialFocus={-1}
>
{popover}
</FloatingFocusManager>
)}
</FloatingPortal>
</FloatingPortal>
)}
</>
);
};
Expand Down
4 changes: 0 additions & 4 deletions packages/Popover/src/__snapshots__/Popover.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ exports[`Popover It should render a snapshot 1`] = `
popover trigger
</span>
</div>
<div
data-floating-ui-portal=""
id=":r2:"
/>
</body>,
"container": <div>
<span
Expand Down
2 changes: 1 addition & 1 deletion packages/TextEditor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"build": "rollup -c rollup.config.js"
},
"dependencies": {
"@floating-ui/react": "^0.24.8",
"@floating-ui/react": "^0.27.3",
"@igloo-ui/button": "^0.10.0",
"@igloo-ui/icon-button": "^1.4.0",
"@igloo-ui/input": "^2.3.2",
Expand Down
34 changes: 17 additions & 17 deletions packages/TextEditor/src/plugins/FloatingLinkEditorPlugin.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import * as React from "react";
import cx from "classnames";
import { type Dispatch, useCallback, useEffect, useRef, useState } from "react";
import {
autoUpdate,
flip,
shift,
FloatingFocusManager,
FloatingPortal,
hide,
offset,
autoUpdate,
useFloating,
shift,
useClick,
useDismiss,
useFloating,
useInteractions,
useTransitionStyles,
hide,
FloatingPortal,
useClick,
FloatingFocusManager
useTransitionStyles
} from "@floating-ui/react";
import cx from "classnames";
import * as React from "react";
import { type Dispatch, useCallback, useEffect, useRef, useState } from "react";

import {
$isAutoLinkNode,
Expand All @@ -38,12 +38,12 @@ import {
} from "lexical";

import IconButton from "@igloo-ui/icon-button";
import Input from "@igloo-ui/input";
import Checkmark from "@igloo-ui/icons/dist/Checkmark";
import Delete from "@igloo-ui/icons/dist/Delete";
import Close from "@igloo-ui/icons/dist/Close";
import Delete from "@igloo-ui/icons/dist/Delete";
import Edit from "@igloo-ui/icons/dist/Edit";
import External from "@igloo-ui/icons/dist/Launch";
import Input from "@igloo-ui/input";

import type { Messages } from "../TextEditor";
import { getSelectedNode } from "../utils/getSelectedNode";
Expand Down Expand Up @@ -335,8 +335,8 @@ function FloatingLinkEditor({
});

return (
<FloatingPortal>
{isMounted && (
isMounted ? (
<FloatingPortal>
<FloatingFocusManager context={context} modal={false} initialFocus={-1}>
<div
ref={refs.setFloating}
Expand All @@ -352,8 +352,8 @@ function FloatingLinkEditor({
{!isLink ? null : linkEditorHTML}
</div>
</FloatingFocusManager>
)}
</FloatingPortal>
</FloatingPortal>
) : null
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/Tooltip/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"dependencies": {
"@igloo-ui/tokens": "^2.1.0",
"@hopper-ui/tokens": "^4.3.2",
"@floating-ui/react": "^0.24.8",
"@floating-ui/react": "^0.27.3",
"classnames": "^2.3.2"
},
"browserslist": [
Expand Down
2 changes: 1 addition & 1 deletion packages/Tooltip/src/Tooltip.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('Tooltip', () => {
const defaultComponentSetup = {
children: 'children',
content: 'tooltip copy',
dataTest: 'tooltip-id',
dataTest: 'tooltip-id'
};

test('It should render a snapshot', (): void => {
Expand Down
28 changes: 14 additions & 14 deletions packages/Tooltip/src/Tooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import * as React from "react";
import cx from "classnames";
import {
arrow,
autoPlacement,
autoUpdate,
flip,
shift,
FloatingPortal,
offset,
autoUpdate,
useFloating,
shift,
useDismiss,
useInteractions,
useTransitionStyles,
autoPlacement,
useHover,
useFloating,
useFocus,
useHover,
useInteractions,
useRole,
FloatingPortal
useTransitionStyles
} from "@floating-ui/react";
import cx from "classnames";
import * as React from "react";

import useDeviceDetect from "./hooks/useDeviceDetect";

Expand Down Expand Up @@ -168,8 +168,8 @@ const Tooltip: React.FunctionComponent<TooltipProps> = ({
return (
<span ref={refs.setReference} className={classes} {...getReferenceProps()}>
{children}
<FloatingPortal>
{isMounted && (
{isMounted && (
<FloatingPortal>
<div
ref={refs.setFloating}
className={tooltipClasses}
Expand All @@ -193,8 +193,8 @@ const Tooltip: React.FunctionComponent<TooltipProps> = ({
style={arrowStyles}
/>
</div>
)}
</FloatingPortal>
</FloatingPortal>
)}
</span>
);
};
Expand Down
4 changes: 0 additions & 4 deletions packages/Tooltip/src/__snapshots__/Tooltip.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ exports[`Tooltip It should render a snapshot 1`] = `
tooltip
</span>
</div>
<div
data-floating-ui-portal=""
id=":r2:"
/>
</body>,
"container": <div>
<span
Expand Down
Loading
Loading