Skip to content

Commit 820a23d

Browse files
committed
Deprecate BorderBox list_id param
Adds a deprecation warning for the `list_id:` param, now superseded by the more general `list_arguments: { id: ... }` introduced in this branch. The deprecated param no longer overrides an id supplied via `list_arguments`.
1 parent f89fdfe commit 820a23d

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

app/components/primer/beta/border_box.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ class BorderBox < Primer::Component
7272

7373
# @param padding [Symbol] <%= one_of(Primer::Beta::BorderBox::PADDING_MAPPINGS.keys) %>
7474
# @param list_arguments [Hash] <%= link_to_system_arguments_docs %>
75+
# @param list_id [String] Deprecated. Use <code>list_arguments: { id: ... }</code> instead.
7576
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
7677
def initialize(padding: DEFAULT_PADDING, list_arguments: {}, **system_arguments)
7778
list_id = system_arguments.delete(:list_id)
79+
deprecation_warn("The `list_id:` param is deprecated. Use `list_arguments: { id: ... }` instead. It will be removed in a future version.") if list_id
7880

7981
@system_arguments = deny_tag_argument(**system_arguments)
8082
@system_arguments[:tag] = :div
@@ -87,7 +89,7 @@ def initialize(padding: DEFAULT_PADDING, list_arguments: {}, **system_arguments)
8789
@system_arguments[:system_arguments_denylist] = { [:p, :pt, :pb, :pr, :pl] => PADDING_SUGGESTION }
8890
@list_arguments = deny_tag_argument(**list_arguments)
8991
@list_arguments[:tag] = :ul
90-
@list_arguments[:id] = list_id if list_id
92+
@list_arguments[:id] ||= list_id if list_id
9193
@list_arguments[:classes] = class_names("Box-list", @list_arguments[:classes])
9294
end
9395

@@ -105,6 +107,12 @@ def before_render
105107
{ aria: { labelledby: header.id } }
106108
)
107109
end
110+
111+
def deprecation_warn(message)
112+
return if Rails.env.production? || silence_deprecations?
113+
114+
::Primer::ViewComponents.deprecation.warn(message)
115+
end
108116
end
109117
end
110118
end

test/components/beta/border_box_test.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,24 @@ def test_renders_the_list_element_with_an_id_if_provided
9191
assert_selector("li.Box-row", count: 1)
9292
end
9393

94+
def test_warns_when_list_id_param_passed
95+
with_silence_deprecations(false) do
96+
::Primer::ViewComponents.deprecation.expects(:warn).with("The `list_id:` param is deprecated. Use `list_arguments: { id: ... }` instead. It will be removed in a future version.").once
97+
render_inline(Primer::Beta::BorderBox.new(list_id: "an-id")) do |component|
98+
component.with_row { "First" }
99+
end
100+
end
101+
end
102+
103+
def test_list_arguments_id_takes_precedence_over_deprecated_list_id
104+
render_inline(Primer::Beta::BorderBox.new(list_id: "old-id", list_arguments: { id: "new-id" })) do |component|
105+
component.with_row { "First" }
106+
end
107+
108+
assert_selector("ul#new-id", count: 1)
109+
assert_no_selector("ul#old-id")
110+
end
111+
94112
def test_renders_condensed
95113
render_inline(Primer::Beta::BorderBox.new(padding: :condensed)) do |component|
96114
component.with_body { "Body" }

0 commit comments

Comments
 (0)