From 5f9092e74581d86c46713243f3107030de10ca3b Mon Sep 17 00:00:00 2001 From: Jon Kirwan <87758239+jon-kirwan@users.noreply.github.com> Date: Tue, 29 Nov 2022 11:53:05 +0000 Subject: [PATCH] Add the keyboard shim for link buttons --- CHANGELOG.md | 4 ++++ lib/govuk_publishing_components/presenters/button_helper.rb | 3 ++- spec/components/button_spec.rb | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c5b863eec..7c3ba74d95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ useful summary for people upgrading their application, not a replication of the commit log. +## Unreleased + +* Add the keyboard shim for link buttons ([PR #3027](https://github.com/alphagov/govuk_publishing_components/pull/3027)) + ## 33.0.0 * **BREAKING** Refactor GA4 analytics event and link trackers ([PR #3057](https://github.com/alphagov/govuk_publishing_components/pull/3057)) diff --git a/lib/govuk_publishing_components/presenters/button_helper.rb b/lib/govuk_publishing_components/presenters/button_helper.rb index 08dd56af30..d15eebbf0c 100644 --- a/lib/govuk_publishing_components/presenters/button_helper.rb +++ b/lib/govuk_publishing_components/presenters/button_helper.rb @@ -38,7 +38,8 @@ def initialize(local_assigns) @info_text_classes << margin_class end @rel = local_assigns[:rel] - @data_attributes = local_assigns[:data_attributes] + @data_attributes = local_assigns[:data_attributes]&.symbolize_keys || {} + @data_attributes[:module] = "govuk-button #{data_attributes[:module]}".strip if link? @margin_bottom = local_assigns[:margin_bottom] @inline_layout = local_assigns[:inline_layout] @target = local_assigns[:target] diff --git a/spec/components/button_spec.rb b/spec/components/button_spec.rb index e83c04d462..823a226953 100644 --- a/spec/components/button_spec.rb +++ b/spec/components/button_spec.rb @@ -27,7 +27,7 @@ def component_name assert_select ".govuk-button[type=submit]", text: "Submit" render_component(text: "Link", href: "#", type: "button") - assert_select "a.govuk-button", text: "Link" + assert_select "a.govuk-button[data-module=\"govuk-button\"]", text: "Link" assert_select "a.govuk-button[type=submit]", false render_component(text: "Button", type: "button") @@ -169,7 +169,7 @@ def component_name }, ) - assert_select "a.govuk-button[data-module='cross-domain-tracking']" + assert_select "a.govuk-button[data-module='govuk-button cross-domain-tracking']" assert_select "a.govuk-button[data-tracking-code='GA-123ABC']" assert_select "a.govuk-button[data-tracking-name='transactionTracker']" end