[Bug Fix] Dialog: keep closed native <dialog> hidden and sync docs controller (#343)

Merged
DJ
5mo ago
+39-12

Problem

After #343 migrated Dialog to the native <dialog> element, dialogs render open by default on https://www.rubyui.com/docs/dialog (and for any gem consumer). The migration left two gaps:

  1. CSS (gem): DialogContent used a bare flex utility. Author-origin CSS overrides the user-agent rule dialog:not([open]) { display: none } regardless of specificity, so a closed <dialog> was forced visible (shown centered, no backdrop, page behind not inert — i.e. not actually a modal).
  2. JS (docs): The docs app bundles its own copy of the Stimulus controller, which was never updated to the native-dialog version and still referenced the removed content target. Console showed Missing target element "content", so triggers threw instead of opening the modal.

Fix

  • gem/lib/ruby_ui/dialog/dialog_content.rb: flex → open:flex (layout applies only when [open]; a closed dialog falls back to the UA display:none).
  • docs/app/javascript/controllers/ruby_ui/dialog_controller.js: synced with the gem's native-dialog controller (dialogTarget / showModal / backdropClick).
  • gem/test/ruby_ui/dialog_test.rb: regression test asserting open:flex (and no bare flex).
  • mcp/data/registry.json: rebuilt.

Testing

cd gem && bundle exec rake → 264 runs, 0 failures + StandardRB clean.

Verified in a real browser against a local docs build (pnpm build && pnpm build:css):

  • Closed (default): dialogs hidden — only triggers visible ✅
  • Trigger click: opens a native modal (backdrop + body scroll lock, :modal true) ✅
  • Close: restores display:none ✅
  • No console errors (previously threw Missing target element "content") ✅

Fixes the regression from #343. Recommend a patch release.

🤖 Generated with Claude Code


Summary by cubic

Fixes the native

regression so closed dialogs stay hidden and docs triggers open a real modal again. Updates gem CSS and syncs the docs Stimulus controller with the native-dialog API.
  • Bug Fixes
    • DialogContent: gate layout with open:flex instead of flex so closed dialogs fallback to UA display:none.
    • Docs controller: switch to dialog target, use showModal/close, handle backdrop clicks, and clear body scroll lock on close.
    • Add regression test for open:flex; rebuild mcp/data/registry.json.