[Bug Fix] Dialog: keep closed native <dialog> hidden and sync docs controller (#343)
Merged
DJ
5mo ago+39+39+01234567890123456789-12-12-01234567890123456789
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:
- CSS (gem):
DialogContentused a bareflexutility. Author-origin CSS overrides the user-agent ruledialog: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). - 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
contenttarget. Console showedMissing 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 UAdisplay: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 assertingopen:flex(and no bareflex).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,
:modaltrue) ✅ - 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 withopen:flexinstead offlexso closed dialogs fallback to UAdisplay:none.- Docs controller: switch to
dialogtarget, useshowModal/close, handle backdrop clicks, and clear body scroll lock on close. - Add regression test for
open:flex; rebuildmcp/data/registry.json.