[Feature] Allow TabsTrigger to render as an anchor via `as:`
Description
Adds an as: option to RubyUI::TabsTrigger (default :button) so a trigger can render as an <a href> instead of a <button>.
This is useful when tabs are actually navigation links โ e.g. server-rendered tabs driven by a query param (?tab=...). The common workaround is to wrap a TabsTrigger (<button>) inside a Link (<a>), which produces a <button> nested inside an <a>. That is invalid HTML and a keyboard/accessibility problem (nested interactive elements). With as: :a, each navigable tab collapses to a single <a> while keeping the trigger's styling and data-* attributes.
Behavior
- Default is unchanged:
TabsTriggerstill renders<button type="button">, so existing client-side tabs are unaffected (fully backward compatible). TabsTrigger(value: ..., as: :a, href: ...)renders<a href>with the same classes anddata-*(data-ruby-ui--tabs-target="trigger", theclick->ruby-ui--tabs#showaction, anddata-value).type="button"is only emitted for the:buttonvariant (it's invalid on an anchor).
The ruby-ui--tabs#show Stimulus controller does not call preventDefault, so the anchor navigates normally while the active state stays driven by the data-* attributes.
Usage
Tabs(default_value: "account", class: "w-96") do
TabsList do
TabsTrigger(value: "account", as: :a, href: "?tab=account") { "Account" }
TabsTrigger(value: "password", as: :a, href: "?tab=password") { "Password" }
end
end
Changes
gem/lib/ruby_ui/tabs/tabs_trigger.rbโ addas:option and conditional element/typerendering.gem/test/ruby_ui/tabs_trigger_test.rbโ new tests: renders as<button>by default, renders as<a href>withas: :a, and preserves triggerdata-*on the anchor.docs/app/views/docs/tabs.rbโ add an "As navigation links" example.
How to test
cd gem
bundle exec rake test TEST=test/ruby_ui/tabs_trigger_test.rb
bundle exec rake # full suite + standardrb
๐ค Generated with Claude Code
Summary by cubic
Add as: to RubyUI::TabsTrigger to render triggers as <a href> for navigation tabs; anchors keep trigger classes and data-* and navigate normally. Default remains <button type="button">, and we now always emit type="button" for any non-anchor trigger to prevent accidental form submissions (e.g., when as: is mistyped).