[Bug Fix] DropdownMenu: fix z-index stacking and default placement (#439)

Merged
DJ
5mo ago
+17-10

Fixes #439

Problems

After the Floating UI port (#158), the DropdownMenu had two issues (reproducible on https://www.rubyui.com/docs/dropdown_menu):

  1. Open menu renders behind sibling elements. On the Placement grid, opening a menu showed it under neighbouring triggers. The container carried a static z-50, and so did every sibling dropdown — equal z-index, so paint order fell back to DOM order and later siblings covered an open menu.
  2. First Usage example: menu detached from the "Open" button. Default placement was top (unusual for a dropdown — convention is bottom), and the demo wrapped the trigger in class: 'w-full', so Floating UI used the full-width wrapper as the reference and centred the menu over it, far from the small button.

Changes

  • dropdown_menu_controller.js (gem + docs copy):
    • default placement top → bottom.
    • set element.style.zIndex only while the menu is open ("50" on open, cleared on close).
  • dropdown_menu.rb: removed the static z-50 from the container. Closed dropdowns now stack in normal flow (no stacking context), so the one open menu — elevated by the controller — always paints above its neighbours.
  • dropdown_menu_docs.rb + docs/app/views/docs/dropdown_menu.rb: dropped w-full from the Usage trigger so the floating reference matches the visible button.

Testing

  • cd gem && bundle exec rake → 237 runs, 0 failures, StandardRB clean.
  • node --check on both controllers.
  • Manual: on the docs dropdown page, the Usage menu now opens directly below the "Open" button, and Placement menus paint above neighbouring triggers.

Screenshots

Before/after to be added.


Summary by cubic

Fixes DropdownMenu stacking so open menus render above siblings, and sets the default placement to open below the trigger. Updates docs and MCP registry so the menu positions relative to the button, not a full-width wrapper.

  • Bug Fixes
    • Removed container z-50; controller now sets zIndex = "50" only while open and clears on close.
    • Changed default placement from top to bottom in both controllers.
    • Docs: dropped w-full from DropdownMenuTrigger; rebuilt MCP registry.json to sync examples.