Anchor menus inside size containers to their button

Merged
JA
1mo ago
+368-9

Summary

Closes #505.

Upstream: pre-flight #519 / upstream PR we-promise/sure#4370 (upstream issue we-promise/sure#4366). #519 is this change ported onto mirror/upstream-main on its own branch (up/floating-ui-container-menus), with the same four app/test files and diff. The two fork-only CI fixes ported from #516 (below) are not part of it.

Before: a "..." menu inside an @container opened far from its button. On Bills › All bills it landed 445px left of the button, which is the container's offset. On a phone it landed above the page header. The Portfolio page's menu did the same, and so did the old inline bill pane in the report.

After: the menu opens against its button. On desktop the right edges align, below the button or flipped above it. On a phone it spans the screen directly under the button.

@floating-ui/utils 0.2.9 counted any container-type ancestor as the containing block of a position: fixed element. Browsers don't, so the menu's coordinates were measured from the container while the browser applied them to the window. 0.2.12 drops that check.

How: only @floating-ui/utils moves, from 0.2.9 to 0.2.12. Both vendored utils files are replaced from the npm tarball, and the importmap version comments are updated. dom and core 1.7.0 accept ^0.2.9, and every name they import is still exported. Apart from the containerType removal, the utils diff is refactoring.

Scope and dependencies

  • Issue: #505 (Issue Gatekeeper review landed as NEEDS_CLARIFICATION. Its one finding is addressed and the plan was revised in place.)
  • Parent PR/branch, if stacked: none
  • Intentionally out of scope: bumping @floating-ui/dom/core to 1.8.0; per-view workarounds that move menus out of containers. The files are vendored from npm because jspm is unreachable from the build sandbox; bin/importmap pin would fetch the same 0.2.12 dist, minified.

Evidence checklist

  • Each issue in this PR has its own acceptance criteria and no unrelated issue work is included. (The two CI fixes are ported verbatim from #516 only so CI can run; see below.)
  • Contract rows touched by this change name existing tests. (No contract rows touched; new BillMenuPositionTest.)
  • Any gate test has an observed failing mutation transcript attached. (Below.)
  • Fixtures used as evidence assert internal consistency. (The bill is created in the test; both assertions measure the menu against its own button.)
  • Financial calculations use BigDecimal and documented rounding points. (N/A: presentation only.)
  • De-identification uses token-shape allowlists; no personal data is included.
  • Files changed, decisions, tests/runtime, risks, and next unblocked issue are documented below.

Files: vendor/javascript/@floating-ui--utils.js, vendor/javascript/@floating-ui--utils--dom.js, config/importmap.rb, test/system/bill_menu_position_test.rb (new). Ported from #516 for CI only: .github/workflows/ci.yml, test/controllers/bills_controller_test.rb.

Validation

Commands and results at the current head (local, Ruby 3.3.6, Chromium 141, 2026-10-22):

  • bin/rails test test/system/bill_menu_position_test.rb on 0.2.12: 2 runs, 3 assertions, 0 failures.
  • Same with only @floating-ui--utils--dom.js restored to 0.2.9 (mutation), using the final assertions (right-edge alignment on desktop, assert_adjacent on both):
    menu is not aligned to its button.
    Expected |948 - 503| (445) to be <= 1.
    menu is 118px from its button, expected it beside it (button {"bottom"=>331, "left"=>315, "right"=>351, "top"=>295}, menu {"bottom"=>177, "left"=>0, "right"=>375, "top"=>61})
    2 runs, 2 assertions, 2 failures
    
  • bin/rails test:system: 215 runs, 0 failures, 0 errors (at the first commit; the later commits touch only the new test and the #516 ports).
  • bin/rails test: 12444 runs, 1 failure. The failure is Provider::OpenaiTest#test_extra_headers_stringifies_nested_values_Ruby-style, which expects Ruby 3.4's Hash#inspect format. It fails only because the sandbox runs Ruby 3.3.6 and is unrelated to this change.
  • bin/rails test test/controllers/bills_controller_test.rb on 2026-10-23 with the #516 port: 103 runs, 0 failures (without it, the skipped-occurrence test errors with RecordNotFound, as in CI).
  • bin/brakeman --no-pager: 0 warnings. bin/rubocop on the changed tests: no offenses. Biome only covers app/javascript/**, and no file there changed.
  • Headless browser, before/after (button right edge vs menu right edge): All bills 1015 vs 570 → 1015 vs 1015. Portfolio 1027 vs 582 → 1027 vs 1027. Overview drawer (no container ancestor) 1439 vs 1439 both before and after.
  • Checked against upstream AGENTS.md: Minitest system test, no new dependency (version bump of an existing pin), commit subjects under 72 characters, no UI or design-token changes.

Risks, blockers, and follow-up

  • Every floating-ui caller (DS::Menu, DS::Popover, DS::Tooltip, the select, merchant_select, tag_select and tooltip controllers) picks up the new utils. Behaviour changes only for elements with a container-type ancestor, which is the fix. The full system suite is green.
  • CI: two failures unrelated to this change, both fixed by #516 and ported here verbatim so CI can run. Both are no-ops once #516 is on main, and neither goes upstream.
    • test_unit failed twice on 47952b3 before any test ran: ECR Public's anonymous quota returned toomanyrequests for postgres:16. Fixed by pulling service images from mirror.gcr.io.
    • On 51496ae the suite then ran and hit one date-dependent error in BillsControllerTest (skipped occurrence from last month). OccurrenceGenerator#generate! starts at the cycle containing today, so from about the 21st of a month the test's last-month occurrence isn't generated. Fixed by pinning the test date with travel_to.
  • Production was still running a pre-7-October image when this was reported (inline bill pane). Deploying current main with this change fixes both the All bills and Portfolio menus.