[Feature] Allow DropdownMenuItem to render as a div via `as:`
Description
Adds an as: option to RubyUI::DropdownMenuItem (default :a, option :div).
By default a DropdownMenuItem renders as <a href>. When an item needs to host its own interactive element — a dialog trigger, a form, etc. — wrapping it in the item's anchor produces a <button> (or <form>) nested inside an <a>. That is invalid HTML and a keyboard/accessibility problem (nested interactive elements). With as: :div the item renders as <div role="menuitem">, so the interactive child lives in a valid div > trigger > button structure while the item keeps its styling, role="menuitem", keyboard navigation and close-on-click behavior.
This mirrors the as: option recently added to TabsTrigger.
Behavior
- Default is unchanged:
DropdownMenuItemstill renders<a href="#">, so existing items are unaffected (backward compatible). DropdownMenuItem(as: :div)renders<div role="menuitem">with the same classes/data-*/role and nohref.hrefis tied to the rendered element (unless @as == :div), so an unexpected/mistypedas:value still falls back to a valid<a href>rather than an anchor missing itshref.
Usage
DropdownMenu do
DropdownMenuTrigger(class: "w-full") { Button(variant: :outline) { "Open" } }
DropdownMenuContent do
DropdownMenuItem(href: "#") { "Edit" }
DropdownMenuItem(as: :div) do
Dialog do
DialogTrigger(class: "w-full text-left") { "Delete" }
DialogContent { "…" }
end
end
end
end
Changes
gem/lib/ruby_ui/dropdown_menu/dropdown_menu_item.rb— addas:option, conditional element rendering, andhreftied to the rendered element.gem/test/ruby_ui/dropdown_menu_item_test.rb— new tests: renders as<a href>by default, renders as<div role="menuitem">withouthrefwhenas: :div, and an unexpectedas:value still renders a valid<a href>.docs/app/views/docs/dropdown_menu.rb— add a "Non-navigational item" example.mcp/data/registry.json— rebuilt to reflect the component change.
How to test
cd gem
bundle exec rake test TEST=test/ruby_ui/dropdown_menu_item_test.rb
bundle exec rake # full suite + standardrb
🤖 Generated with Claude Code
Summary by cubic
Adds an as: option to DropdownMenuItem so items can render as a <div> for non-navigational content (e.g. dialog or form triggers) without nesting interactive elements. Default remains <a href>, so this is backward compatible.
- New Features
DropdownMenuItem(as: :div)renders<div role="menuitem">and omitshref.- Keeps styling,
role="menuitem", keyboard navigation, and close-on-click. hrefonly applies to<a>; unexpectedas:values fall back to a valid<a href>.- Added a docs example and tests.