Skip to content

Commit

Permalink
Merge pull request #773 from alphagov/add-back-link-data-attributes
Browse files Browse the repository at this point in the history
Feed data attributes to back link
  • Loading branch information
benthorner authored Feb 27, 2019
2 parents 7a4b0ba + 887e0f5 commit 2238021
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

## Unreleased

* Support data attributes for the back-link component (PR #773)
* Create shared helper for components (PR #759)
* Use delegated event handlers for checkbox events (PR #770)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<%
text ||= t('components.back_link.back')
data_attributes ||= nil
%>
<%= link_to text,
<%= link_to(
text,
href,
class: %w(
gem-c-back-link
govuk-back-link
)
%>
class: %w(gem-c-back-link govuk-back-link),
data: data_attributes
) %>
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ examples:
data:
text: 'Back to document list'
href: '#'
with_data_attributes:
data:
href: '#'
data_attributes:
tracking: GT-1234
9 changes: 7 additions & 2 deletions spec/components/back_link_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ def component_name

it "renders a back link correctly" do
render_component(href: '/back-me')
assert_select ".govuk-back-link[href=\"/back-me\"]", text: "Back"
assert_select '.govuk-back-link[href="/back-me"]', text: "Back"
end

it "can render in welsh" do
I18n.with_locale(:cy) { render_component(href: '/back-me') }
assert_select ".govuk-back-link[href=\"/back-me\"]", text: "Yn ôl"
assert_select '.govuk-back-link[href="/back-me"]', text: "Yn ôl"
end

it "renders a back link with data attributes" do
render_component(href: '/back-me', data_attributes: { tracking: "GT-123" })
assert_select '.govuk-back-link[data-tracking="GT-123"]'
end
end

0 comments on commit 2238021

Please sign in to comment.