Skip to content

Commit 958c1c9

Browse files
jacksonpiresclaude
andcommitted
[Bug Fix] Emit type="button" for any non-anchor TabsTrigger
Tie the `type="button"` attribute to the element actually rendered (`unless @as == :a`) instead of an exact `@as == :button` check. An unexpected/mistyped `as:` value fell through to the `<button>` branch without a type, which defaults to `type="submit"` and could trigger accidental form submission. Issue identified by cubic. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 3c429f6 commit 958c1c9

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

gem/lib/ruby_ui/tabs/tabs_trigger.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def default_attrs
3333
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
3434
]
3535
}
36-
base[:type] = :button if @as == :button
36+
base[:type] = :button unless @as == :a
3737
base
3838
end
3939
end

gem/test/ruby_ui/tabs_trigger_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ def test_renders_as_anchor_with_href_when_as_a
2222
refute_match(/type="button"/, output)
2323
end
2424

25+
def test_unexpected_as_value_still_renders_a_typed_button
26+
output = phlex { RubyUI.TabsTrigger(value: "account", as: :buton) { "Account" } }
27+
28+
assert_match(/\A<button/, output)
29+
assert_match(/type="button"/, output)
30+
end
31+
2532
def test_keeps_trigger_data_attributes_when_rendered_as_anchor
2633
output = phlex { RubyUI.TabsTrigger(value: "account", as: :a, href: "/account") { "Account" } }
2734

0 commit comments

Comments
 (0)