Skip to content

Commit

Permalink
Allow consumers to set ActionList item content's tag (#1880)
Browse files Browse the repository at this point in the history
  • Loading branch information
camertron authored Mar 11, 2023
1 parent b3b94e9 commit 7a160a4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilled-mugs-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/view-components': patch
---

Allow consumers to set ActionList item content's tag
14 changes: 8 additions & 6 deletions app/components/primer/alpha/action_list/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,14 @@ def initialize(
SIZE_MAPPINGS[@size]
)

if @href && !@disabled
@content_arguments[:tag] = :a
@content_arguments[:href] = @href
else
@content_arguments[:tag] = :button
@content_arguments[:onclick] = on_click if on_click
unless @content_arguments[:tag]
if @href && !@disabled
@content_arguments[:tag] = :a
@content_arguments[:href] = @href
else
@content_arguments[:tag] = :button
@content_arguments[:onclick] = on_click if on_click
end
end

@description_wrapper_arguments = {
Expand Down
8 changes: 8 additions & 0 deletions test/components/alpha/action_list_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ def test_manual_dividers
{ type: :item, href: "/item3" }
]
end

def test_allows_custom_item_tag
render_inline(Primer::Alpha::ActionList.new(aria: { label: "List" })) do |component|
component.with_item(label: "Item 1", content_arguments: { tag: :"clipboard-copy" })
end

assert_selector "clipboard-copy.ActionListContent"
end
end
end
end

0 comments on commit 7a160a4

Please sign in to comment.