Skip to content

feat(react-headless-components-preview): adopt anchored container queries for arrow placement#36112

Open
mainframev wants to merge 6 commits into
microsoft:masterfrom
mainframev:fix/headless-popover-implementation
Open

feat(react-headless-components-preview): adopt anchored container queries for arrow placement#36112
mainframev wants to merge 6 commits into
microsoft:masterfrom
mainframev:fix/headless-popover-implementation

Conversation

@mainframev
Copy link
Copy Markdown
Contributor

@mainframev mainframev commented May 6, 2026

Supports the JS-driven data-placement attribute as source of truth for popover-arrow styling with a CSS-native solution based on Chrome 143+'s anchored container queries (container-type: anchored + @container anchored(fallback: …)). The placement-observer still runs on older Chromium so arrow direction stays correct on older versions.

@mainframev mainframev changed the title fix(react-headless-components-preview): fix(react-headless-components-preview): improve placement-observer May 6, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

📊 Bundle size report

Package & Exports Baseline (minified/GZIP) PR Change
react-headless-components-preview
react-headless-components-preview: entire library
107.577 kB
31.646 kB
108.254 kB
31.892 kB
677 B
246 B

🤖 This report was generated against 0307f02ca1bc383b15fca2c2dc62ba2113fd7c5f

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

Pull request demo site: URL

@mainframev mainframev force-pushed the fix/headless-popover-implementation branch from 25dee94 to f815971 Compare May 6, 2026 19:17
refactor(headless-popover): refactor implementation
@mainframev mainframev force-pushed the fix/headless-popover-implementation branch from f815971 to 1bd5814 Compare May 6, 2026 20:20
@mainframev mainframev force-pushed the fix/headless-popover-implementation branch 2 times, most recently from c18c393 to 3550016 Compare May 6, 2026 22:02
@mainframev mainframev changed the title fix(react-headless-components-preview): improve placement-observer fix(react-headless-components-preview): adopt anchored container queries for arrow placement May 6, 2026
@mainframev mainframev self-assigned this May 6, 2026
@mainframev mainframev force-pushed the fix/headless-popover-implementation branch from 3550016 to c11b03b Compare May 6, 2026 22:07
@mainframev mainframev marked this pull request as ready for review May 6, 2026 22:10
@mainframev mainframev requested a review from a team as a code owner May 6, 2026 22:10

if (win && supportsAnchoredContainerQueries(win)) {
// Chrome 143+: opt into `@container anchored(fallback: …)` queries.
node.style.setProperty('container-type', 'anchored');
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to be careful with this, as it doesn't remove some JS from the bundle,
and what is more important, consumers have to write two versions of styles, as there is no data-placement attribute when the @container anchored(fallback: …) branch is active

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in the latest push:

  • data-placement is now always written (in both branches of the supportsAnchoredContainerQueries(win) check). Consumers can author a single set of [data-placement="…"] rules that works everywhere.
  • @container anchored(fallback: …) becomes a pure override layer that only flips the arrow when the browser actually activates a position-try-fallback. The duplicated [data-position]/[data-align] rule set in popover.module.css is gone.
  • On the JS-bundle concern: the observer still has to run on browsers without anchored container queries, so it stays in the bundle. The split into a separate PR (this one) is exactly so we can keep discussing whether the CSS-only path is worth the trade-off.

The refactor changes you LGTM'd are now in #36192.

Copy link
Copy Markdown
Contributor

@dmytrokirpa dmytrokirpa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, except container queries, can we separate move that change to a separate PR, as we'll probably need more feedback on the idea


if (win && supportsAnchoredContainerQueries(win)) {
// Chrome 143+: opt into `@container anchored(fallback: …)` queries.
node.style.setProperty('container-type', 'anchored');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to be careful with this, as it doesn't remove some JS from the bundle,
and what is more important, consumers have to write two versions of styles, as there is no data-placement attribute when the @container anchored(fallback: …) branch is active

@dmytrokirpa dmytrokirpa self-requested a review May 11, 2026 14:06
@mainframev mainframev changed the title fix(react-headless-components-preview): adopt anchored container queries for arrow placement feat(react-headless-components-preview): adopt anchored container queries for arrow placement May 12, 2026
mainframev added a commit to mainframev/fluentui that referenced this pull request May 12, 2026
Address review feedback on microsoft#36112: when container-type: anchored is
supported, data-placement was being removed, forcing consumers to author
two parallel rule sets (one keyed on [data-placement], one on
[data-position]+[data-align] inside @supports). Now data-placement is
always written, so the base [data-placement] rules work everywhere and
@container anchored(fallback: …) becomes a pure override layer for new
browsers.
@mainframev mainframev force-pushed the fix/headless-popover-implementation branch from c11b03b to b1ca4c5 Compare May 12, 2026 09:58
@mainframev mainframev force-pushed the fix/headless-popover-implementation branch from b1ca4c5 to d6768ac Compare May 12, 2026 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants