Skip to content

Commit 0647fed

Browse files
authored
Allow ActionList item content to be supplied by positional arg (#2995)
1 parent 53abaa6 commit 0647fed

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

.changeset/brown-fireants-reflect.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/view-components': patch
3+
---
4+
5+
Allow ActionList item content to be supplied by positional arg

app/components/primer/alpha/action_list/item.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@ class Item < Primer::Component
4141
# Description content that complements the item's label, with optional test_selector.
4242
# See `ActionList`'s `description_scheme` argument for layout options.
4343
#
44+
# @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")`.
4445
# @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.
45-
renders_one :description, -> (test_selector: nil) do
46-
Primer::BaseComponent.new(tag: "span", classes: "ActionListItem-description", test_selector: test_selector) { content }
46+
renders_one :description, -> (legacy_content = nil, test_selector: nil) do
47+
Primer::BaseComponent.new(tag: "span", classes: "ActionListItem-description", test_selector: test_selector).tap do |desc|
48+
desc.with_content(legacy_content) if legacy_content
49+
end
4750
end
4851

4952
# An icon, avatar, SVG, or custom content that will render to the left of the label.

test/components/alpha/action_list_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ def test_item_description_test_selector
3939
assert_selector(".ActionListItem-description[data-test-selector='foo']", text: "My description")
4040
end
4141

42+
def test_item_description_legacy_content
43+
render_inline(Primer::Alpha::ActionList.new(aria: { label: "List" })) do |component|
44+
component.with_item(label: "Item 1", href: "/item1") do |item|
45+
item.with_description("My description")
46+
end
47+
end
48+
49+
assert_selector(".ActionListItem-description", text: "My description")
50+
end
51+
4252
def test_item_trailing_visual_text
4353
render_preview(:item, params: { trailing_visual_text: "trailing visual text" })
4454

0 commit comments

Comments
 (0)