Skip to content

Commit

Permalink
Merge pull request #4549 from alphagov/attachment-link-component-wrapper
Browse files Browse the repository at this point in the history
BREAKING Use component wrapper on attachment link component
  • Loading branch information
AshGDS authored Jan 15, 2025
2 parents ed19497 + 9e9a5b5 commit 4043e62
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

* **BREAKING** Use component wrapper on big number component ([PR #4550](https://github.com/alphagov/govuk_publishing_components/pull/4550))
* **BREAKING** Use component wrapper on attachment component ([PR #4545](https://github.com/alphagov/govuk_publishing_components/pull/4545))
* **BREAKING** Use component wrapper on attachment link component ([PR #4549](https://github.com/alphagov/govuk_publishing_components/pull/4549))
* Add 'draggable' attribute to component wrapper helper ([PR #4544](https://github.com/alphagov/govuk_publishing_components/pull/4544))

## 48.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

attachment = GovukPublishingComponents::Presenters::AttachmentHelper.new(attachment)
target ||= nil
data_attributes ||= {}
url_data_attributes ||= {}
attributes = []
if attachment.content_type_name
content = if attachment.content_type_abbr
Expand All @@ -30,11 +30,14 @@
class: "gem-c-attachment-link__attribute",
)
end

component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns)
component_helper.add_class("gem-c-attachment-link")
%>
<%= tag.span(class: "gem-c-attachment-link") do %>
<%= tag.span(**component_helper.all_attributes) do %>
<%= link_to(attachment.title, attachment.url,
class: "govuk-link",
target: target,
data: data_attributes) -%>
data: url_data_attributes) -%>
<%= raw("(#{attributes.join(', ')})") if attributes.any? -%>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ accessibility_criteria: |
Attachment links within paragraphs of text do not need to meet the 24 by 24 CSS pixels requirements.
shared_accessibility_criteria:
- link
uses_component_wrapper_helper: true
examples:
default:
data:
Expand Down Expand Up @@ -58,10 +59,10 @@ examples:
title: "Temporary snow ploughs: guidance note"
url: https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/259634/temporary-snow-ploughs.pdf
target: _blank
with_data_attributes:
with_data_attributes_on_url:
data:
attachment:
title: "Temporary snow ploughs: guidance note"
url: https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/259634/temporary-snow-ploughs.pdf
data_attributes:
url_data_attributes:
gtm: "attachment-preview"
2 changes: 1 addition & 1 deletion spec/components/attachment_link_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def component_name
title: "Attachment",
url: "attachment",
},
data_attributes: { gtm: "attachment-preview" },
url_data_attributes: { gtm: "attachment-preview" },
)
assert_select "a.govuk-link[data-gtm='attachment-preview']"
end
Expand Down

0 comments on commit 4043e62

Please sign in to comment.