From 296750204abf9ea159395a0c991e7ebd6a445907 Mon Sep 17 00:00:00 2001 From: diondiondion Date: Fri, 26 Jun 2026 11:24:51 +0200 Subject: [PATCH] Replace react-overlays with Floating UI (#39621) --- .../components/account_header/name.tsx | 23 +- .../components/alt_text_badge/index.tsx | 35 ++- .../mastodon/components/autosuggest_input.jsx | 16 +- .../components/autosuggest_textarea.jsx | 25 ++- .../mastodon/components/dropdown/index.tsx | 38 ++-- .../mastodon/components/dropdown/utils.ts | 17 -- .../mastodon/components/dropdown_menu.tsx | 47 ++-- .../components/form_fields/combobox_field.tsx | 86 ++++---- .../components/hover_card_controller.tsx | 24 +-- .../mastodon/components/learn_more_link.tsx | 21 +- .../mastodon/components/popover/index.tsx | 203 ++++++++++++++++++ .../mastodon/components/popover/portal.tsx | 21 ++ .../components/status/boost_button.tsx | 2 +- .../status_action_bar/remove_quote_hint.tsx | 25 +-- .../account_edit/components/image_edit.tsx | 6 +- .../account_timeline/components/filters.tsx | 30 +-- .../alt_text_modal/components/info_button.tsx | 22 +- .../components/emoji_picker_dropdown.jsx | 70 ++---- .../compose/components/language_dropdown.tsx | 66 ++---- .../compose/components/privacy_dropdown.tsx | 27 +-- .../components/select_with_label.tsx | 70 +++--- .../features/ui/components/boost_modal.tsx | 9 - .../ui/components/hashtag_menu_controller.tsx | 45 ++-- .../mastodon/hooks/useOnClickOutside.ts | 62 +++--- .../styles/mastodon/components.scss | 8 +- package.json | 2 +- yarn.lock | 115 ++++------ 27 files changed, 587 insertions(+), 528 deletions(-) delete mode 100644 app/javascript/mastodon/components/dropdown/utils.ts create mode 100644 app/javascript/mastodon/components/popover/index.tsx create mode 100644 app/javascript/mastodon/components/popover/portal.tsx diff --git a/app/javascript/mastodon/components/account_header/name.tsx b/app/javascript/mastodon/components/account_header/name.tsx index e66affae1b..4b6f9d1b44 100644 --- a/app/javascript/mastodon/components/account_header/name.tsx +++ b/app/javascript/mastodon/components/account_header/name.tsx @@ -1,12 +1,10 @@ -import { useCallback, useId, useRef, useState } from 'react'; +import { useCallback, useId, useState } from 'react'; import type { FC } from 'react'; import { defineMessages, FormattedMessage, useIntl } from 'react-intl'; import classNames from 'classnames'; -import Overlay from 'react-overlays/esm/Overlay'; - import { useAccount } from '@/mastodon/hooks/useAccount'; import { useRelationship } from '@/mastodon/hooks/useRelationship'; import { useAppSelector } from '@/mastodon/store'; @@ -20,6 +18,7 @@ import { CopyButton } from '../copy_button'; import { DisplayName } from '../display_name'; import { Icon } from '../icon'; import { NavigationFocusTarget } from '../navigation_focus_target'; +import { Popover } from '../popover'; import { AccountBadges } from './badges'; import classes from './styles.module.scss'; @@ -82,7 +81,8 @@ const AccountNameHelp: FC<{ const accessibilityId = useId(); const intl = useIntl(); const [open, setOpen] = useState(false); - const triggerRef = useRef(null); + const [triggerElement, setTriggerElement] = + useState(null); const handleClick = useCallback(() => { setOpen((prev) => !prev); @@ -94,7 +94,7 @@ const AccountNameHelp: FC<{ <> - } - onHide={handleClick} - offset={[5, 5]} + {({ props }) => (
)} -
+ ); }; diff --git a/app/javascript/mastodon/components/alt_text_badge/index.tsx b/app/javascript/mastodon/components/alt_text_badge/index.tsx index 535ba3d1b6..64e120ea4f 100644 --- a/app/javascript/mastodon/components/alt_text_badge/index.tsx +++ b/app/javascript/mastodon/components/alt_text_badge/index.tsx @@ -4,22 +4,14 @@ import { FormattedMessage, useIntl } from 'react-intl'; import classNames from 'classnames'; -import type { - OffsetValue, - UsePopperOptions, -} from 'react-overlays/esm/usePopper'; -import Overlay from 'react-overlays/Overlay'; - import CloseIcon from '@/material-icons/400-24px/close.svg?react'; import { useSelectableClick } from 'mastodon/hooks/useSelectableClick'; import { IconButton } from '../icon_button'; +import { Popover } from '../popover'; import classes from './styles.module.scss'; -const offset = [0, 4] as OffsetValue; -const popperConfig = { strategy: 'fixed' } as UsePopperOptions; - export const AltTextBadge: React.FC<{ description: string; className?: string; @@ -28,7 +20,9 @@ export const AltTextBadge: React.FC<{ const uniqueId = useId(); const popoverId = `${uniqueId}-popover`; const titleId = `${uniqueId}-title`; - const buttonRef = useRef(null); + const [buttonElement, setButtonElement] = useState( + null, + ); const popoverRef = useRef(null); const [open, setOpen] = useState(false); @@ -41,8 +35,8 @@ export const AltTextBadge: React.FC<{ const handleClose = useCallback(() => { setOpen(false); - buttonRef.current?.focus(); - }, [setOpen]); + buttonElement?.focus(); + }, [buttonElement]); const [handleMouseDown, handleMouseUp] = useSelectableClick(handleClose); @@ -50,7 +44,7 @@ export const AltTextBadge: React.FC<{ <>