Skip to content

Commit

Permalink
Add component wrapper helper to the list component
Browse files Browse the repository at this point in the history
Also removes the shared_helper functionality, as margin_bottom is now handled within the component wrapper.
  • Loading branch information
AshGDS committed Jan 10, 2025
1 parent 6f6e033 commit 6561d1e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 26 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
## Unreleased

* **BREAKING** Change devolved nations component type option ([PR #4535](https://github.com/alphagov/govuk_publishing_components/pull/4535))
* **BREAKING** Add component wrapper helper to intervention component ([PR #4378](https://github.com/alphagov/govuk_publishing_components/pull/4378))
* **BREAKING** Add component wrapper helper to the list component ([PR #4441](https://github.com/alphagov/govuk_publishing_components/pull/4441))
* Use component wrapper on subscription links ([PR #4525](https://github.com/alphagov/govuk_publishing_components/pull/4525))
* Use component wrapper on success alert component ([PR #4527](https://github.com/alphagov/govuk_publishing_components/pull/4527))
* Use component wrapper on summary card component ([PR #4528](https://github.com/alphagov/govuk_publishing_components/pull/4528))
* Use component wrapper on summary list component ([PR #4529](https://github.com/alphagov/govuk_publishing_components/pull/4529))
* Use component wrapper on translation nav component ([PR #4530](https://github.com/alphagov/govuk_publishing_components/pull/4530))
* Use component wrapper on warning text component ([PR #4351](https://github.com/alphagov/govuk_publishing_components/pull/4531))
* Remove govspeak advisory component ([PR #4349](https://github.com/alphagov/govuk_publishing_components/pull/4349))
* **BREAKING**: Add component wrapper helper to intervention component ([PR #4378](https://github.com/alphagov/govuk_publishing_components/pull/4378))
* Use component wrapper on super navigation header ([PR #4534](https://github.com/alphagov/govuk_publishing_components/pull/4534))

## 47.0.0
Expand Down
18 changes: 6 additions & 12 deletions app/views/govuk_publishing_components/components/_list.html.erb
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
<%
aria_label ||= nil
extra_spacing ||= nil
id ||= nil
items ||= []
list_type ||= "unordered"
visible_counters ||= nil

shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)

classes = %w[gem-c-list govuk-list]
classes << "govuk-list--bullet" if visible_counters and list_type === "unordered"
classes << "govuk-list--number" if visible_counters and list_type === "number"
classes << "govuk-list--spaced" if extra_spacing
# Setting the `margin_bottom` to 4 is the same as the default margin - so we
# can omit the override class. To do this we leave out `4` from the array:
classes << shared_helper.get_margin_bottom if [0,1,2,3,5,6,7,8,9].include?(local_assigns[:margin_bottom])
component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns)
component_helper.add_class("gem-c-list govuk-list")
component_helper.add_class("govuk-list--bullet") if visible_counters and list_type === "unordered"
component_helper.add_class("govuk-list--number") if visible_counters and list_type === "number"
component_helper.add_class("govuk-list--spaced") if extra_spacing

# Default list type is unordered list.
list_tag = "ul"
Expand All @@ -23,7 +17,7 @@
list_tag = "ol" if list_type === "number"
%>
<% if items.any? %>
<%= content_tag list_tag, class: classes, id: id, "aria-label": aria_label do %>
<%= content_tag list_tag, **component_helper.all_attributes do %>
<% items.each do |item| %>
<li><%= raw(item) %></li>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ body: |
The `items` parameter can include HTML to display - such as links or another
list. This HTML can either be directly coded or come from another component.
uses_component_wrapper_helper: true
accessibility_criteria: |
The list must:
Expand All @@ -31,7 +32,8 @@ examples:
unordered_list_with_aria-label:
description: "A list with an aria-label"
data:
aria_label: "A list of delicious chocolate bars."
aria:
label: "A list of delicious chocolate bars."
<<: *default-example-data
unordered_list_with_bullet_points:
description: "An unordered list with visible bullet points."
Expand Down
15 changes: 3 additions & 12 deletions spec/components/list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ def component_name

it "adds an aria-label" do
render_component(
aria_label: "An aria-label to give this context.",
aria: {
label: "An aria-label to give this context.",
},
items: ["Test item", "Another test item"],
)

Expand Down Expand Up @@ -124,17 +126,6 @@ def component_name
assert_select '.gem-c-list.govuk-\!-margin-bottom-7'
end

it "defaults to no bottom margin if an incorrect value is passed" do
render_component(
margin_bottom: 20,
items: [
"<a href='https://example.com/'>Test item</a>",
"<a href='https://example.com/'>Another test item</a>",
],
)
assert_select "[class^='govuk-\!-margin-bottom-']", false
end

it "has no margin class added by default" do
render_component(
items: [
Expand Down

0 comments on commit 6561d1e

Please sign in to comment.