From ead12171a2e058fc6a49fa31a3f3f8e364629002 Mon Sep 17 00:00:00 2001 From: Max Lehmann Date: Thu, 5 Sep 2019 13:50:19 +0100 Subject: [PATCH] Adjust focus states This adds the govuk-link class to multiple links throughout the codebase in order to inherit the correct styles, and updates related tests. Where the class is overridden by govuk-template the styles have been updated to use a temporary mixin to enforce the correct colour state and the class is locally overridden where white links are needed. --- .../stylesheets/components/_back-to-top.scss | 3 --- .../components/_important-metadata.scss | 12 ++++++++---- .../stylesheets/components/_published-dates.scss | 11 ++++++----- .../components/_publisher-metadata.scss | 2 +- app/assets/stylesheets/helpers/_parts.scss | 2 +- .../_govuk-template-link-focus-override.scss | 9 +++++++++ app/presenters/content_item/linkable.rb | 6 +++--- app/presenters/content_item/parts.rb | 2 +- app/presenters/fatality_notice_presenter.rb | 2 +- app/presenters/specialist_document_presenter.rb | 2 +- app/views/components/_back-to-top.html.erb | 2 +- app/views/components/_print-link.html.erb | 2 +- app/views/components/_published-dates.html.erb | 4 ++-- test/presenters/case_study_presenter_test.rb | 12 ++++++------ test/presenters/content_item/linkable_test.rb | 4 ++-- test/presenters/content_item/parts_test.rb | 8 ++++---- test/presenters/publication_presenter_test.rb | 6 +++--- .../specialist_document_presenter_test.rb | 3 ++- test/presenters/speech_presenter_test.rb | 6 +++--- .../statistics_announcement_presenter_test.rb | 2 +- test/presenters/travel_advice_presenter_test.rb | 16 ++++++++-------- 21 files changed, 64 insertions(+), 52 deletions(-) create mode 100644 app/assets/stylesheets/mixins/_govuk-template-link-focus-override.scss diff --git a/app/assets/stylesheets/components/_back-to-top.scss b/app/assets/stylesheets/components/_back-to-top.scss index 6d786c4f0..baf181e0b 100644 --- a/app/assets/stylesheets/components/_back-to-top.scss +++ b/app/assets/stylesheets/components/_back-to-top.scss @@ -4,9 +4,6 @@ margin-left: govuk-spacing(3); margin-right: govuk-spacing(3); - &:focus { - @include govuk-focused-text; - } } .app-c-back-to-top__icon { diff --git a/app/assets/stylesheets/components/_important-metadata.scss b/app/assets/stylesheets/components/_important-metadata.scss index 4175d88c6..d90184bf1 100644 --- a/app/assets/stylesheets/components/_important-metadata.scss +++ b/app/assets/stylesheets/components/_important-metadata.scss @@ -1,7 +1,6 @@ .app-c-important-metadata { - @include white-links; background: $govuk-blue; - color: $white; + color: govuk-colour("white"); padding: govuk-spacing(3); @include media(tablet) { @@ -30,7 +29,12 @@ .app-c-important-metadata__definition { font-weight: bold; - a:focus { - @include govuk-focused-text; + .app-link { + color: govuk-colour("white"); + + &:focus { + @include govuk-template-link-focus-override; + } } + } diff --git a/app/assets/stylesheets/components/_published-dates.scss b/app/assets/stylesheets/components/_published-dates.scss index 922b6cebe..10b124218 100644 --- a/app/assets/stylesheets/components/_published-dates.scss +++ b/app/assets/stylesheets/components/_published-dates.scss @@ -6,18 +6,19 @@ .app-c-published-dates__toggle { display: none; - &:focus { - @include govuk-focused-text; - } - .js-enabled & { display: inline-block; } + + &:focus { + @include govuk-template-link-focus-override; + } + } .app-c-published-dates__history-link { &:focus { - @include govuk-focused-text; + @include govuk-template-link-focus-override; } } diff --git a/app/assets/stylesheets/components/_publisher-metadata.scss b/app/assets/stylesheets/components/_publisher-metadata.scss index 2ff229647..c82bcec9c 100644 --- a/app/assets/stylesheets/components/_publisher-metadata.scss +++ b/app/assets/stylesheets/components/_publisher-metadata.scss @@ -8,7 +8,7 @@ font-weight: bold; &:focus { - @include govuk-focused-text; + @include govuk-template-link-focus-override; } } diff --git a/app/assets/stylesheets/helpers/_parts.scss b/app/assets/stylesheets/helpers/_parts.scss index 56a2eec8c..97810d96e 100644 --- a/app/assets/stylesheets/helpers/_parts.scss +++ b/app/assets/stylesheets/helpers/_parts.scss @@ -29,7 +29,7 @@ display: block; &:focus { - @include govuk-focused-text; + @include govuk-template-link-focus-override; } } } diff --git a/app/assets/stylesheets/mixins/_govuk-template-link-focus-override.scss b/app/assets/stylesheets/mixins/_govuk-template-link-focus-override.scss new file mode 100644 index 000000000..a32091473 --- /dev/null +++ b/app/assets/stylesheets/mixins/_govuk-template-link-focus-override.scss @@ -0,0 +1,9 @@ +// TODO: Remove when appropriate +// govuk_template overrides the styles set by +// govuk-frontend 3.0.0. This mixin is intended as a temporary fix +// to ensure focus styles are as expected in apps using govuk_template + +@mixin govuk-template-link-focus-override { + @include govuk-focused-text; + color: govuk-colour("black") !important; +} diff --git a/app/presenters/content_item/linkable.rb b/app/presenters/content_item/linkable.rb index 945d1e829..45a5f553c 100644 --- a/app/presenters/content_item/linkable.rb +++ b/app/presenters/content_item/linkable.rb @@ -37,7 +37,7 @@ def links_group(types) def organisations_ordered_by_importance organisations_with_emphasised_first.map do |link| - link_to(link["title"], link["base_path"]) + link_to(link["title"], link["base_path"], class: "govuk-link") end end @@ -54,12 +54,12 @@ def emphasised_organisations def link_for_type(type, link) return link_for_world_location(link) if type == "world_locations" - link_to(link["title"], link["base_path"]) + link_to(link["title"], link["base_path"], class: "govuk-link") end def link_for_world_location(link) base_path = WorldLocationBasePath.for(link) - link_to(link["title"], base_path) + link_to(link["title"], base_path, class: "govuk-link") end end end diff --git a/app/presenters/content_item/parts.rb b/app/presenters/content_item/parts.rb index 94fe0bea8..02dfcf40f 100644 --- a/app/presenters/content_item/parts.rb +++ b/app/presenters/content_item/parts.rb @@ -86,7 +86,7 @@ def current_part def part_links parts.map.with_index(1) do |part, position| if part['slug'] != current_part['slug'] - link_to part['title'], part['full_path'], + link_to part['title'], part['full_path'], class: "govuk-link", data: { track_category: 'contentsClicked', track_action: "content_item #{position}", diff --git a/app/presenters/fatality_notice_presenter.rb b/app/presenters/fatality_notice_presenter.rb index 3b2c99865..eb0418269 100644 --- a/app/presenters/fatality_notice_presenter.rb +++ b/app/presenters/fatality_notice_presenter.rb @@ -18,7 +18,7 @@ def image def important_metadata super.tap do |m| if field_of_operation - m.merge!('Field of operation' => link_to(field_of_operation.title, field_of_operation.path)) + m.merge!('Field of operation' => link_to(field_of_operation.title, field_of_operation.path, class: "govuk-link app-link")) end end end diff --git a/app/presenters/specialist_document_presenter.rb b/app/presenters/specialist_document_presenter.rb index 09d43425c..f2dfcba8b 100644 --- a/app/presenters/specialist_document_presenter.rb +++ b/app/presenters/specialist_document_presenter.rb @@ -168,7 +168,7 @@ def facet_block(facet, allowed_value) def facet_link(label, value, key) finder_base_path = finder['base_path'] - link_to(label, "#{finder_base_path}?#{key}%5B%5D=#{value}") + link_to(label, "#{finder_base_path}?#{key}%5B%5D=#{value}", class: "govuk-link app-link") end def first_published_at_facet_key diff --git a/app/views/components/_back-to-top.html.erb b/app/views/components/_back-to-top.html.erb index 34b70141d..3f5c70898 100644 --- a/app/views/components/_back-to-top.html.erb +++ b/app/views/components/_back-to-top.html.erb @@ -1,7 +1,7 @@ <% text ||= t('content_item.contents', default: "Contents") %> - diff --git a/app/views/components/_print-link.html.erb b/app/views/components/_print-link.html.erb index 4afa3dbc3..ed21070d0 100644 --- a/app/views/components/_print-link.html.erb +++ b/app/views/components/_print-link.html.erb @@ -5,7 +5,7 @@