From b2b62a4888aa6c8675efb0c38edbee21f2fc96c6 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 | 3 +++ lib/govuk_publishing_components/presenters/button_helper.rb | 4 ++++ spec/components/button_spec.rb | 4 ++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d97a60b7d1..7b91ae3a5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ 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)) + ## 32.1.0 * Calculate viewport width correctly for navbar in Chrome and Firefox when Mac scrollbars are enabled ([PR #3016](https://github.com/alphagov/govuk_publishing_components/pull/3016)) 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