From 91c66c6689c2db0ea7e2e198ce3d4d70e3c21a5d Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Sun, 5 Apr 2026 19:38:04 -0400 Subject: [PATCH] Replace Floating UI with CSS Anchor Positioning in Popover MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Swap the Popover component from using @floating-ui/dom to native CSS Anchor Positioning (position-anchor, position-area, position-try-fallbacks). - Popover now uses position-area for placement with anchor-center alignment - Automatic flip via position-try-fallbacks: flip-block, flip-inline - Viewport-aware hiding via position-visibility: anchors-visible - Offset via margin on the anchor-facing side - Arrow positioned with anchor(center) for precise anchor-relative centering - FloatingUI component and anchorTo modifier remain unchanged for direct use - Menu component unchanged — derives from Popover API which stays compatible - Deprecated args (flipOptions, shiftOptions, middleware) accepted but ignored - Added popover rendering tests for CSS Anchor Positioning styles - Updated floating-ui docs with disclaimer about CSS Anchor Positioning replacement - Updated popover docs to reflect new positioning approach Co-Authored-By: Claude Opus 4.6 (1M context) --- .../5-floaty-bits/floating-ui.gjs.md | 12 +- .../templates/5-floaty-bits/popover.gjs.md | 31 ++- ember-primitives/src/anchor-position.ts | 3 + .../src/anchor-position/modifier.ts | 43 ++++ .../src/anchor-position/placement.ts | 180 +++++++++++++ ember-primitives/src/components/menu.gts | 10 +- ember-primitives/src/components/popover.gts | 243 +++++++----------- packages/docs-support/src/site-css/shell.css | 11 + test-app/tests/popover/rendering-test.gts | 141 ++++++++++ 9 files changed, 501 insertions(+), 173 deletions(-) create mode 100644 ember-primitives/src/anchor-position.ts create mode 100644 ember-primitives/src/anchor-position/modifier.ts create mode 100644 ember-primitives/src/anchor-position/placement.ts create mode 100644 test-app/tests/popover/rendering-test.gts diff --git a/docs-app/app/templates/5-floaty-bits/floating-ui.gjs.md b/docs-app/app/templates/5-floaty-bits/floating-ui.gjs.md index ff3f898e3..76d603831 100644 --- a/docs-app/app/templates/5-floaty-bits/floating-ui.gjs.md +++ b/docs-app/app/templates/5-floaty-bits/floating-ui.gjs.md @@ -1,13 +1,19 @@ # Floating UI -The `FloatingUI` component provides a wrapper for using [Floating UI](https://floating-ui.com/), for associating a floating element to an anchor element (such as for menus, popovers, etc). - -The usage of a 3rd-party library will be removed when [CSS Anchor Positioning](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_anchor_positioning) lands and is widely supported (This component and modifier will still exist for the purpose of wiring up the ids between anchor and target). +**Higher-level components use CSS Anchor Positioning.** ``, ``, and other built-in components now use native [CSS Anchor Positioning](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_anchor_positioning) instead of Floating UI. For most use cases, prefer [``](/5-floaty-bits/popover.md) or [``](/5-floaty-bits/menu.md) directly. + +The `` component and `anchorTo` modifier remain available for: +- **Environments without CSS Anchor Positioning support** — if you need to support browsers that don't yet implement CSS Anchor Positioning, use `` directly for JS-based positioning +- **Advanced use cases** where you need direct access to [Floating UI](https://floating-ui.com/) middleware + +Note that Floating UI is entirely JS-based and does not use CSS Anchor Positioning internally — these are two separate positioning approaches. +The `FloatingUI` component provides a wrapper for using [Floating UI](https://floating-ui.com/), for associating a floating element to an anchor element (such as for menus, popovers, etc). + Several of Floating UI's functions and [middleware](https://floating-ui.com/docs/middleware) are used to create an experience out of the box that is useful and expected. See Floating UI's [documentation](https://floating-ui.com/docs/getting-started) for more information on any of the following included functionality. diff --git a/docs-app/app/templates/5-floaty-bits/popover.gjs.md b/docs-app/app/templates/5-floaty-bits/popover.gjs.md index 8906b3ced..e0d6e6fbb 100644 --- a/docs-app/app/templates/5-floaty-bits/popover.gjs.md +++ b/docs-app/app/templates/5-floaty-bits/popover.gjs.md @@ -1,12 +1,12 @@ # Popover -Popovers are built with [Floating UI][docs-floating-ui], a set of utilities for making floating elements relate to each other with minimal configuration. The `` component uses the [Popover API](https://developer.mozilla.org/en-US/docs/Web/API/Popover_API) for layering, which totally solves z-index and overflow clipping issues, no portals needed. +Popovers use [CSS Anchor Positioning][docs-anchor] for positioning floating elements relative to their anchor, with automatic flip fallbacks via `position-try-fallbacks` and viewport-aware visibility via `position-visibility`. No JavaScript positioning library needed. + +The `` component uses the [Popover API](https://developer.mozilla.org/en-US/docs/Web/API/Popover_API) for layering, which totally solves z-index and overflow clipping issues — no portals needed. One thing to note is that the position of the popover can _escape_ the boundary of a [ShadowDom][docs-shadow-dom] -- all demos on this docs site for `ember-primitives` use a `ShadowDom` to allow for isolated CSS usage within the demos. -[docs-floating-ui]: /5-floaty-bits/floating-ui.md -[docs-floating]: https://floating-ui.com/ -[docs-popper]: https://popper.js.org/ +[docs-anchor]: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_anchor_positioning [docs-shadow-dom]: https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_shadow_DOM