Skip to content

fix(#3643): Popover overflows right viewport edge — add position-try-fallbacks and position-try-order#3791

Draft
Copilot wants to merge 3 commits intodevfrom
copilot/fix-popover-right-edge-overflow
Draft

fix(#3643): Popover overflows right viewport edge — add position-try-fallbacks and position-try-order#3791
Copilot wants to merge 3 commits intodevfrom
copilot/fix-popover-right-edge-overflow

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 9, 2026

The CSS Anchor Positioning rewrite hardcoded inset-inline-start: anchor(left) with no overflow handling, causing the popover to extend off-screen when the trigger is near the right viewport edge.

Before (the change)

Popover always left-aligned with the trigger. When the trigger was near the right viewport edge, the popover extended off-screen.

After (the change)

Popover.svelte — CSS only

  • Added position-try-fallbacks: flip-inline to .popover-content base rule. When the left-aligned position would overflow, the browser tries inset-inline-end: anchor(right) — right-aligning the popover with the trigger's right edge.
  • Added position-try-order: most-inline-size to .popover-content base rule. This ensures the browser picks whichever alignment (left or right) gives the element the most inline width. This is necessary because width: fit-content causes Chrome to shrink the popover to the available space rather than detecting overflow, so without this flip-inline would never trigger near the right edge.
  • Changed position-try-fallbacks: noneflip-inline on .use-anchor-based-positioning.position-above so the same fix applies for position="above".
  • position-right retains position-try-fallbacks: none — directional intent is explicit there.

Make sure that you've checked the boxes below before you submit the PR

  • I have read and followed the setup steps
  • I have created necessary unit tests
  • I have tested the functionality in both React and Angular.

Steps needed to test

  1. Navigate to /bugs/3643 in the React PRS playground (npm run serve:prs:react)
  2. Open the right-side popover triggers — popover should be right-aligned with the trigger and stay within the viewport
  3. Confirm left-side triggers still open left-aligned (no regression)
  4. Repeat for the position="above" row and the MenuButton row

@netlify
Copy link
Copy Markdown

netlify bot commented Apr 9, 2026

Deploy Preview for benji-docs-previews failed.

Name Link
🔨 Latest commit c7cec3e
🔍 Latest deploy log https://app.netlify.com/projects/benji-docs-previews/deploys/69d7f9c8668f750008d2e815

…r viewport overflow

Closes #3643

Add `position-try-fallbacks: flip-inline` to the `.popover-content` base CSS so
the browser automatically right-aligns the popover when left-alignment would cause
it to overflow the right viewport edge.

Also update `.use-anchor-based-positioning.position-above` to use `flip-inline`
instead of `none` so the horizontal overflow fix applies to above-positioned
popovers too. The `position-right` variant retains `none` since it has intentional
directional positioning.

Add PR test page (bug3643) with three test cases demonstrating the fix.

Agent-Logs-Url: https://github.com/GovAlta/ui-components/sessions/89c8f24d-cd80-41af-9b51-78538427be41

Co-authored-by: bdfranck <1479091+bdfranck@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix popover overflow when trigger is near viewport boundary fix(#3643): Popover overflows right viewport edge — add position-try-fallbacks: flip-inline Apr 9, 2026
Copilot AI requested a review from bdfranck April 9, 2026 17:32
Copy link
Copy Markdown
Collaborator

@bdfranck bdfranck left a comment

Choose a reason for hiding this comment

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

@copilot Here's what I see in the latest version of Chrome.

The left-side trigger popover is left-aligned with the anchor...

image

...but the right-side trigger is still left-aligned with the anchor. It's just shorter to not leave the viewport.

image

Should I expect to see this? I was hoping to see it right-aligned with the anchor item.

…line selection

The flip-inline fallback wasn't triggering because Chrome sizes the popover
via width:fit-content constrained to the available space (from anchor's left
to viewport right), so the element appears to "fit" and position-try-fallbacks
never fires.

Adding position-try-order: most-inline-size tells the browser to pick whichever
try-option yields the most inline width for the element. Near the right edge the
flip-inline (right-aligned) option wins because it has more space to the left.

Agent-Logs-Url: https://github.com/GovAlta/ui-components/sessions/d5d27eb5-05a5-41a3-b3dd-fcc6efd29db4

Co-authored-by: bdfranck <1479091+bdfranck@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 9, 2026

@copilot Here's what I see in the latest version of Chrome.

The left-side trigger popover is left-aligned with the anchor......

The root cause was that width: fit-content computes the element's width within the available space (from anchor's left edge to the viewport right), so Chrome was shrinking the popover to fit rather than detecting overflow — meaning flip-inline never triggered.

Added position-try-order: most-inline-size (commit c7cec3e). This tells the browser to compare how much inline width each try-option gives the element and pick the widest one. Near the right edge, the flip-inline (right-aligned) fallback wins because anchor.right pixels of space are available to the left vs. the narrow slice remaining to the right. For left-side triggers the primary left-aligned option wins, so there's no change in behaviour there.

Copilot AI changed the title fix(#3643): Popover overflows right viewport edge — add position-try-fallbacks: flip-inline fix(#3643): Popover overflows right viewport edge — add position-try-fallbacks and position-try-order Apr 9, 2026
Copilot AI requested a review from bdfranck April 9, 2026 19:12
@GovAlta GovAlta deleted a comment from Copilot AI Apr 10, 2026
@GovAlta GovAlta deleted a comment from Copilot AI Apr 10, 2026
@GovAlta GovAlta deleted a comment from Copilot AI Apr 10, 2026
@GovAlta GovAlta deleted a comment from Copilot AI Apr 10, 2026
@GovAlta GovAlta deleted a comment from Copilot AI Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Popover: Overflows right edge when trigger is near viewport boundary

2 participants