Skip to content

[popups] Fix collision padding off-by-one on the biased side - #5143

Merged
atomiks merged 2 commits into
mui:masterfrom
atomiks:claude/exciting-robinson-7011f8
Jul 1, 2026
Merged

atomiks merged 2 commits into
mui:masterfrom
atomiks:claude/exciting-robinson-7011f8

Conversation

@atomiks

@atomiks atomiks commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #5131.

collisionPadding was being applied 1px farther from the edge than requested on the popup's preferred-side axis (e.g. the top gap measured 6px for a default collisionPadding={5}).

Cause

A 1px "preferred side" bias was added so that an iOS soft-keyboard-centered input doesn't undesirably flip its popup to the top. That bias was baked directly into the shared collisionPadding object, so instead of only nudging flip()'s decision, it leaked into every middleware that reads collisionPadding:

  • shift() rested the popup 1px farther from the biased edge than requested.
  • size() computed --available-height 1px too small.
  • the arrow limitShift offset was also slightly off.

Fix

Normalize collisionPadding to the user's raw values, and apply the directional bias only inside flip(). The flip() padding is algebraically unchanged (collisionPadding + bias + directionalBias), so the iOS anti-flip behavior is fully preserved — the bias just no longer shifts the resting position.

This lives in the shared useAnchorPositioning, so it applies to every anchored component (Popover, Tooltip, Menu, Select, Combobox, Preview Card, etc.), but the user-visible symptom was reported on Popover.

Verification

I tested the Combobox page in iOS (iPhone) and couldn't see the popup flip to the top by default. Tested every input on the demos page.

  • Added a regression test in PopoverPositioner.test.tsx asserting the popup rests exactly at collisionPadding from the colliding edge (fails at 13 pre-fix, passes at 12 post-fix).
  • All 205 positioner tests pass across components.
  • Reproduced the off-by-one in the browser and confirmed the fix (6px → 5px, --available-height 968px → 969px).

@atomiks atomiks added component: popover Changes related to the popover component. type: bug It doesn't behave as expected. labels Jun 30, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jun 30, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@5143
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@5143
    

commit: 6034fc0

The 1px "preferred side" bias (added so an iOS keyboard-centered input
doesn't flip its popup to the top) was baked into the shared
`collisionPadding` object, so it leaked into every middleware rather than
just `flip()`. As a result `shift()` rested the popup 1px farther from the
biased edge than requested, and `size()` computed `--available-height` 1px
too small.

Normalize `collisionPadding` to the user's raw values and apply the
directional bias only inside `flip()`. The `flip()` padding is unchanged
algebraically, so the iOS anti-flip behavior is preserved while the resting
position now honors `collisionPadding` exactly.

Fixes mui#5131
@atomiks
atomiks force-pushed the claude/exciting-robinson-7011f8 branch from 7c05e0a to 17b6969 Compare June 30, 2026 10:57
@atomiks atomiks changed the title [popover] Fix collision padding off-by-one on the biased side [popups] Fix collision padding off-by-one on the biased side Jun 30, 2026
@atomiks atomiks added scope: all components Widespread work has an impact on almost all components. and removed component: popover Changes related to the popover component. labels Jun 30, 2026
@netlify

netlify Bot commented Jun 30, 2026

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 7c05e0a
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a43a0aef896000008bb6769
😎 Deploy Preview https://deploy-preview-5143--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@code-infra-dashboard

code-infra-dashboard Bot commented Jun 30, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react ▼-16B(0.00%) ▼-19B(-0.01%)

Details of bundle changes

Performance

Total duration: 1,362.16 ms -260.08 ms(-16.0%) | Renders: 78 (+0)

Test Duration Renders
Tabs mount (200 instances) 228.64 ms ▼-68.54 ms(-23.1%) 4 (+0)
Slider mount (300 instances) 161.44 ms ▼-53.64 ms(-24.9%) 3 (+0)
Tooltip mount (300 contained roots) 47.54 ms ▼-25.76 ms(-35.1%) 1 (+0)
Popover mount (300 instances) 70.48 ms ▼-22.54 ms(-24.2%) 1 (+0)
Dialog mount (300 instances) 55.91 ms ▼-15.58 ms(-21.8%) 1 (+0)

9 tests within noise — details


Check out the code infra dashboard for more information about this PR.

@atomiks
atomiks marked this pull request as ready for review June 30, 2026 11:02
@netlify

netlify Bot commented Jun 30, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 6034fc0
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a44b930c2a5b90008c2899f
😎 Deploy Preview https://deploy-preview-5143--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@flaviendelangle flaviendelangle left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

PR review

This is a tightly-scoped positioning fix in the shared useAnchorPositioning: the iOS anti-flip 1px bias was baked into the normalized collisionPadding object and leaked into shift()/size(), shifting the resting position and --available-height 1px off. The fix normalizes to raw user values and re-adds the bias only inside flip(). Nothing is merge-blocking — the flip() padding is algebraically unchanged so the anti-flip behavior is preserved, and the fix is well-targeted and tested.

Bugs (0)

No findings.

I verified the algebra across every consumer of collisionPadding:

  • flip(): old (user + biasTop) + bias vs new user + bias + biasTop — identical, so the iOS anti-flip is fully preserved and still strictly exceeds the size() padding (precedence maintained).
  • shift() / size(): now use raw user padding — the intended fix.
  • limitShift: uses raw padding; correct.

Tests (0)

No findings.

The added PopoverPositioner.test.tsx regression test is well-constructed: it pins the anchor near the bottom to force a flip to the top edge, then asserts the resting top equals collisionPadding exactly (fails at 13 pre-fix, passes at 12 post-fix). Because the flipped popup collides with the top edge, this also indirectly exercises the corrected size()/shift() padding. triggerStyle, Trigger, isJSDOM, and waitFor are all in scope, and the test is correctly Chromium-only via it.skipIf(isJSDOM).

Simplifications (0)

No findings.

Docs (0)

No findings.

ℹ️ Note (PR description only, not the code): the description lists a third symptom — "the arrow limitShift offset was also slightly off." That claim doesn't hold. biasTop/biasBottom are nonzero only when sideParam is top/bottom, but limitShift's offsetAmount for a top/bottom (y-axis) placement sums the cross-axis left + right paddings, where biasLeft/biasRight are always 0 — and symmetrically for left/right popups. So limitShift never carried the directional bias, and its change here is a harmless no-op. Worth correcting in the PR body to avoid implying a behavior change that isn't there; no code action needed.

Verdict

Approve — a minimal, algebraically-verified fix with a targeted regression test; the only note is a minor inaccuracy in the PR description, not the code.


🤖 Review generated with Claude Code

@atomiks
atomiks merged commit d6f51ca into mui:master Jul 1, 2026
6 checks passed
@atomiks
atomiks deleted the claude/exciting-robinson-7011f8 branch July 1, 2026 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: all components Widespread work has an impact on almost all components. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[popover] Collision padding top is off by 1px

2 participants