Repository navigation
[popups] Fix transform origin for start/end alignment - #5015
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,230.08 ms +117.86 ms(+10.6%) | Renders: 76 (+0) | Paint: 1,985.47 ms +194.34 ms(+10.8%)
10 tests within noise — details Metric alarms
…and 1 more metric alarm — details Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
cf30a2a to
01641f2
Compare
flaviendelangle
left a comment
There was a problem hiding this comment.
PR review
This fixes the scale-animation transform origin for start/end aligned popups without an arrow: the origin now sits on the popup's aligned edge (0%/100%) instead of a clamped point derived from the virtual arrow. The rewrite is correct and the RTL/shift/overlap branches precisely mirror Floating UI's own positioning logic (verified against @floating-ui/core). Nothing is merge-blocking; test coverage is thorough (center/start/end, RTL, shifted, overlap, arrow-present, sideOffset, horizontal sides).
Bugs (0)
No findings.
Tests (0)
No findings.
Simplifications (0)
No findings.
Docs (0)
No findings.
Notes
ℹ️ 1. platform.isRTL! relies on the default DOM platform being in use
Location: packages/react/src/utils/useAnchorPositioning.ts:388 (new code)
crossOrigin =
(renderedAlign === 'start') === (isVertical && platform.isRTL!(floating))
? '100%'
: '0%';platform.isRTL is optional in Floating UI's Platform interface, so the non-null assertion assumes a platform that implements it. This holds today — Base UI never passes a custom platform to useFloating, and the default DOM platform defines isRTL (floating-ui.dom.mjs:492) — and matching platform.isRTL(floating) is exactly right here because that is the same signal Floating UI uses to position the alignment. Just a heads-up that the ! encodes that invariant rather than guarding it; a ?. with a false fallback would degrade to LTR instead of throwing if that ever changes. Reasonable to leave as-is.
Verdict
Approve — correct, well-tested fix; the RTL/shift/overlap handling matches Floating UI's positioning math, and the only note is an optional defensive tweak.
🤖 Review generated with Claude Code
|
i had my lil DX review skill take a look at this and it seems to think should we include the cross-axis value from perhaps we need to add end/RTL/horizontal and narrow anchor test coverage as well. DX reviewThe core fix is sound, but the new edge-origin calculation overlooks other middleware that can move the popup away from its aligned edge. Nothing is blocking, though offset positioning should be handled before merge. Findings (1)1. 🟠 Alignment offsets leave the transform origin detached from the anchorSource: Math.abs(isVertical ? middlewareData.shift?.x || 0 : middlewareData.shift?.y || 0) <= 1The edge-origin branch only checks displacement from The virtual arrow can similarly apply User scenario: A dropdown uses Recommendation: Derive the origin from every cross-axis displacement, not only What is already sound
VerdictApprove after nits — account for non- 🤖 Review generated with Codex |
50ce634 to
2b6a738
Compare
25921a4 to
d017843
Compare
d017843 to
d68c540
Compare
|
@jjenzz I believe the current PR is correct, based on this recording. Fixing it causes it to slide (second column): Screen.Recording.2026-08-25.at.10.32.12.pm.mov |
ironically i think that's exactly what Codex was suggesting the fix was supposed to avoid, so yeah we don't want that 🙈 silly Codex. |
Before: https://base-ui.com/react/components/combobox#input-inside-popup
After: https://deploy-preview-5015--base-ui.netlify.app/react/components/combobox#input-inside-popup
The
transformOriginmiddleware inuseAnchorPositioningalways derived the cross-axis origin from thearrowmiddleware data. Without an arrow element, a zero-size virtual arrow is used, which the arrow middleware centers against the anchor. That's correct forcenteralignment (the origin tracks the anchor's center even when the popup shifts), but forstart/endthe popup's edge is aligned with the anchor's edge, so the scale animation emanated from the anchor's center partway into the popup — and for an anchor wider than the popup, from a clamped point near the popup's far edge.The cross-axis origin is now picked explicitly:
centeralign → anchor's center via the virtual arrow (unchanged).start/endalign → the popup's aligned edge:0%/100%. Uses the rendered alignment and Floating UI's RTL platform info, so it stays correct after alignment flips and in RTL.start/endalign → anchor's center via the virtual arrow, since the popup edge no longer lines up with the anchor edge.The middleware is also simplified: instead of a four-entry side map plus a separate overlap string, it computes one cross-axis and one side-axis coordinate (the anchor-overlap case for context menus is folded into the side coordinate) and joins them in axis order.
Added Chromium tests asserting the exact
--transform-originvalue for center/start/end alignment, RTL start/end alignment, shifted start alignment, horizontal sides,sideOffset,alignOffset, and the arrow-present case.