Anchor menus inside size containers to their button

Merged
JA
1mo ago
+362-5

Closes #4366

Fork pre-flight: jaysbeekay/sure#519, from the same branch and commit. Its CI runs and reviews, and the fork issue with the triage plan (jaysbeekay/sure#505), are there.

Problem

A DS::Menu whose button sits inside an element with container-type (Tailwind @container) opens away from its button. It is offset up and left by that element's distance from the viewport's top-left corner. On main this affects every row "..." menu on Bills > All bills, in both the list and the table layout. On a wide window the menu lands over unrelated content, and on a phone the full-width menu can open above the page header.

The cause is in the vendored @floating-ui/utils 0.2.9. Its isContainingBlock counts any containerType other than normal as the containing block of a position: fixed element. Browsers do not, so floating-ui returns coordinates relative to the container while the browser applies them to the viewport.

Change

  • Bump @floating-ui/utils from 0.2.9 to 0.2.12. 0.2.12 removes the containerType clause from isContainingBlock. No other file changes.
  • vendor/javascript/@floating-ui--utils.js and @floating-ui--utils--dom.js are replaced with dist/floating-ui.utils.mjs and dist/floating-ui.utils.dom.mjs from the npm 0.2.12 tarball. Below a two-line source header, each file is byte-identical to the tarball file, and the tarball matches the registry's published sha512 integrity.
  • The version comments on the two pins in config/importmap.rb are updated.
  • @floating-ui/dom and @floating-ui/core 1.7.0 both declare @floating-ui/utils: ^0.2.9. Every name they import or re-export from utils and utils/dom is still exported by 0.2.12, and the export lists of the two versions are identical. Apart from the containerType removal, the diff from 0.2.9 to 0.2.12 is refactoring: regexes in place of array lookups, a cached isWebKit, hoisted constants. So floating-ui elements outside a size container behave as before. That covers DS::Menu, DS::Popover, DS::Tooltip, and the select, merchant_select, tag_select and tooltip controllers.

Left out on purpose: bumping dom and core, and per-view workarounds such as moving menus out of containers or a custom platform per controller.

Screenshots

Captured by a system test against the test fixtures: before on main at 7917bc1e4, after on this branch. Bills > All bills with the first row's "..." menu open.

Before (@floating-ui/utils 0.2.9)After (0.2.12)
Before: the menu opens at the top left of the page, away from its buttonAfter: the menu opens under its button

Before, the menu opens at the top left of the page, a container's width away from its button. After, it opens under the button.

Tests

New test/system/bill_menu_position_test.rb opens the first row menu inside the @container on Bills > All bills and measures the menu against its own button:

  • Desktop (1400x1400): the menu's right edge is within 1px of the button's (placement: "bottom-end"), and the menu sits beside the button.
  • Phone (375x812): the menu sits beside the button.
  • "Beside" means a gap of 0 to 20px, measured below the button or above it when flip() placed the menu on top. A legitimate flip therefore cannot fail the test.

On this branch, against remote Chromium (selenium/standalone-chromium), both tests pass. With both vendored utils files restored to main's 0.2.9 they fail: desktop Expected |936 - 475| (461) to be <= 1; phone menu is 128px from its button. A node check of isContainingBlock gives true for container-type: inline-size and size on 0.2.9 and false on 0.2.12. transform, filter, will-change: transform and contain: paint stay true on both.

  • bin/rails test: 12474 runs, 0 failures, 0 errors, 36 skips.
  • test/system/bill_menu_position_test.rb: 2 runs, 0 failures (remote Chromium). The full system suite runs in CI.
  • bin/rubocop: no offenses. bin/brakeman --no-pager: no warnings. Biome covers app/javascript/** only, and no file there changed.

Summary by CodeRabbit

  • Chores
    • Updated positioning utilities, including refinements to placement calculations and padding defaults.
  • Tests
    • Added checks that bill menus remain close to their buttons on desktop and phone-sized screens, including desktop edge alignment.