Skip to content

Commit

Permalink
Allow ActionList item content to be supplied by positional arg (#2995)
Browse files Browse the repository at this point in the history
  • Loading branch information
camertron authored Aug 5, 2024
1 parent 53abaa6 commit 0647fed
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/brown-fireants-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/view-components': patch
---

Allow ActionList item content to be supplied by positional arg
7 changes: 5 additions & 2 deletions app/components/primer/alpha/action_list/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ class Item < Primer::Component
# Description content that complements the item's label, with optional test_selector.
# See `ActionList`'s `description_scheme` argument for layout options.
#
# @param legacy_content [String] Slot content, provided for backwards-compatibility. Pass a content block instead, or call `with_content`, eg. `component.with_description { "My description" }` or `component.with_description.with_content("My description")`.
# @param test_selector [String] The value of this argument is set as the value of a `data-test-selector` HTML attribute on the description element.
renders_one :description, -> (test_selector: nil) do
Primer::BaseComponent.new(tag: "span", classes: "ActionListItem-description", test_selector: test_selector) { content }
renders_one :description, -> (legacy_content = nil, test_selector: nil) do
Primer::BaseComponent.new(tag: "span", classes: "ActionListItem-description", test_selector: test_selector).tap do |desc|
desc.with_content(legacy_content) if legacy_content
end
end

# An icon, avatar, SVG, or custom content that will render to the left of the label.
Expand Down
10 changes: 10 additions & 0 deletions test/components/alpha/action_list_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ def test_item_description_test_selector
assert_selector(".ActionListItem-description[data-test-selector='foo']", text: "My description")
end

def test_item_description_legacy_content
render_inline(Primer::Alpha::ActionList.new(aria: { label: "List" })) do |component|
component.with_item(label: "Item 1", href: "/item1") do |item|
item.with_description("My description")
end
end

assert_selector(".ActionListItem-description", text: "My description")
end

def test_item_trailing_visual_text
render_preview(:item, params: { trailing_visual_text: "trailing visual text" })

Expand Down

0 comments on commit 0647fed

Please sign in to comment.