Skip to content

AnchoredOverlay: Add Popover API, modifications to CSS anchor positioning#7677

Open
TylerJDev wants to merge 23 commits intomainfrom
tylerjdev/add-popover-support-css-anchor-positioning
Open

AnchoredOverlay: Add Popover API, modifications to CSS anchor positioning#7677
TylerJDev wants to merge 23 commits intomainfrom
tylerjdev/add-popover-support-css-anchor-positioning

Conversation

@TylerJDev
Copy link
Member

@TylerJDev TylerJDev commented Mar 18, 2026

Prerequisite to https://github.com/github/primer/issues/6448, part of https://github.com/github/primer/issues/6431

Utilizes the Popover API to power our CSS anchor positioning in AnchoredOverlay. Both the popover support and CSS anchor positioning are behind the primer_react_css_anchor_positioning feature flag.

Changelog

New

  • Adds popover support to AnchoredOverlay

Changed

  • Small modifications, bug fixes towards CSS anchor positioning

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; if selected, include a brief description as to why

Testing & Reviewing

Merge checklist

@changeset-bot
Copy link

changeset-bot bot commented Mar 18, 2026

🦋 Changeset detected

Latest commit: a39e179

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added staff Author is a staff member integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm labels Mar 18, 2026
@github-actions
Copy link
Contributor

⚠️ Action required

👋 Hi, this pull request contains changes to the source code that github/github-ui depends on. If you are GitHub staff, test these changes with github/github-ui using the integration workflow. Check the integration testing docs for step-by-step instructions. Or, apply the integration-tests: skipped manually label to skip these checks.

@primer
Copy link
Contributor

primer bot commented Mar 19, 2026

🤖 Lint issues have been automatically fixed and committed to this PR.

@TylerJDev TylerJDev force-pushed the tylerjdev/add-popover-support-css-anchor-positioning branch from 69db3ec to 1c6dadf Compare March 23, 2026 13:45
@github-actions github-actions bot temporarily deployed to storybook-preview-7677 March 23, 2026 13:55 Inactive
@TylerJDev TylerJDev added the update snapshots 🤖 Command that updates VRT snapshots on the pull request label Mar 24, 2026
@github-actions github-actions bot temporarily deployed to storybook-preview-7677 March 24, 2026 15:14 Inactive
@github-actions github-actions bot removed the update snapshots 🤖 Command that updates VRT snapshots on the pull request label Mar 24, 2026
@github-actions github-actions bot temporarily deployed to storybook-preview-7677 March 24, 2026 15:31 Inactive
@TylerJDev TylerJDev requested a review from liuliu-dev March 24, 2026 20:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces Popover API support to AnchoredOverlay (behind the primer_react_css_anchor_positioning feature flag) and updates the CSS anchor positioning approach, including adding an opt-out for rendering overlays in a Portal.

Changes:

  • Add disablePortal support to Overlay to allow rendering without a Portal when desired.
  • Update AnchoredOverlay to integrate Popover API (popover="manual", showPopover()), and to set anchor/position anchor styles via JS.
  • Extend unit/e2e coverage and Storybook examples (including a “Multiple Overlays” scenario) and add a changeset for a minor release.

Reviewed changes

Copilot reviewed 8 out of 17 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/react/src/Overlay/Overlay.tsx Adds disablePortal prop and uses it to bypass Portal rendering.
packages/react/src/AnchoredOverlay/AnchoredOverlay.tsx Adds Popover API wiring + JS-managed anchor-name / position-anchor setup.
packages/react/src/AnchoredOverlay/AnchoredOverlay.test.tsx Updates tests for new portal behavior and feature-flag-specific behavior.
packages/react/src/AnchoredOverlay/AnchoredOverlay.module.css Removes wrapper/anchor classes; adjusts anchored overlay styles for popover behavior.
packages/react/src/AnchoredOverlay/AnchoredOverlay.features.stories.tsx Adds “Multiple Overlays” story to validate multiple instances.
packages/react/src/ActionMenu/ActionMenu.test.tsx Removes assertions tied to the removed .Anchor CSS class.
e2e/components/AnchoredOverlay.test.ts Adds multi-overlay screenshot coverage.
.playwright/snapshots/** Adds new snapshots for the “Multiple Overlays” story.
.changeset/soft-pianos-carry.md Declares a minor release for the new AnchoredOverlay behavior behind the flag.

renderAnchor={props => <Button {...props}>Anchor Button</Button>}
onPositionChange={onPositionChange}
className={className}
{...overlayProps}
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

AnchoredOverlayTestComponent is spreading the overlayProps test setting directly onto <AnchoredOverlay> ({...overlayProps}), which passes disablePortal as a top-level prop instead of as overlayProps={...}. This should be passed via the overlayProps prop (e.g. overlayProps={overlayProps}), otherwise TS should reject it and the test won't be exercising the intended behavior.

Suggested change
{...overlayProps}
overlayProps={overlayProps}

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@primer-integration
Copy link

👋 Hi from github/github-ui! Your integration PR is ready: https://github.com/github/github-ui/pull/16986

@primer-integration
Copy link

Integration test results from github/github-ui:

Passed  CI   Passed
Waiting  VRT   Waiting
Waiting  Projects   Waiting

Copy link
Contributor

@liuliu-dev liuliu-dev left a comment

Choose a reason for hiding this comment

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

Looks great! ✨

Just a few questions to make sure I understand it correctly.

onClick: onAnchorClick,
onKeyDown: onAnchorKeyDown,
...(cssAnchorPositioning ? {className: classes.Anchor} : {}),
...(cssAnchorPositioning ? {'data-anchor': '', popoverTarget: popoverId} : {}),
Copy link
Contributor

Choose a reason for hiding this comment

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

I couldn't find data-anchor used anywhere in the CSS, is this for future styles?

Comment on lines +274 to +292
// Track the overlay element so we can re-run the effect when it changes.
// This is necessary when using a Portal, as React re-renders can replace
// the DOM node, causing the popover to lose its :popover-open state.
const overlayElement = overlayRef.current

useLayoutEffect(() => {
// Read ref inside effect to get the value after child refs are attached
const currentOverlay = overlayRef.current

if (!cssAnchorPositioning || !open || !currentOverlay) return
currentOverlay.style.setProperty('position-anchor', `--anchored-overlay-anchor-${id}`)
try {
if (!currentOverlay.matches(':popover-open')) {
currentOverlay.showPopover()
}
} catch {
// Ignore if popover is already showing or not supported
}
}, [cssAnchorPositioning, open, overlayElement, id, overlayRef])
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious about this part. Is this because when a Portal remounts, it creates a new Overlay element and :popover-open is lost on this new element?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm staff Author is a staff member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants