Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING Use component wrapper on attachment link component #4549

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading