From 28d408e651cf6393a0add87f7d5231af89fe002c Mon Sep 17 00:00:00 2001 From: Jon Kirwan <87758239+jon-kirwan@users.noreply.github.com> Date: Tue, 18 Oct 2022 15:49:41 +0100 Subject: [PATCH] Add the keyboard shim for link buttons --- CHANGELOG.md | 1 + lib/govuk_publishing_components/presenters/button_helper.rb | 4 ++++ spec/components/button_spec.rb | 4 ++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0bec66878..151ad357db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * Share links allow data attributes ([PR #3072](https://github.com/alphagov/govuk_publishing_components/pull/3072)) * Update to LUX 304 ([PR #3070](https://github.com/alphagov/govuk_publishing_components/pull/3070)) +* Add the keyboard shim for link buttons ([PR #3027](https://github.com/alphagov/govuk_publishing_components/pull/3027)) ## 32.1.0 diff --git a/lib/govuk_publishing_components/presenters/button_helper.rb b/lib/govuk_publishing_components/presenters/button_helper.rb index bc257e23fa..63541fe61c 100644 --- a/lib/govuk_publishing_components/presenters/button_helper.rb +++ b/lib/govuk_publishing_components/presenters/button_helper.rb @@ -37,6 +37,10 @@ def initialize(local_assigns) end @rel = local_assigns[:rel] @data_attributes = local_assigns[:data_attributes] + if href.present? + @data_attributes ||= {} + @data_attributes[:module] = ["govuk-button", @data_attributes[:module]].reject(&:blank?).join(" ") + end @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 f0585948aa..1ac114e58b 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