govuk_publishing_components 37.1.0 → 37.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/config/govuk_publishing_components_manifest.js +0 -2
  3. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-core.js +6 -0
  4. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-schemas.js +2 -2
  5. data/app/assets/javascripts/govuk_publishing_components/lib/cookie-settings.js +109 -0
  6. data/app/assets/javascripts/govuk_publishing_components/load-analytics.js +83 -60
  7. data/app/assets/stylesheets/component_guide/application.scss +1 -1
  8. data/app/assets/stylesheets/govuk_publishing_components/components/_contents-list.scss +1 -1
  9. data/app/assets/stylesheets/govuk_publishing_components/components/_image-card.scss +3 -3
  10. data/app/assets/stylesheets/govuk_publishing_components/components/_modal-dialogue.scss +1 -1
  11. data/app/assets/stylesheets/govuk_publishing_components/components/_search.scss +2 -2
  12. data/app/assets/stylesheets/govuk_publishing_components/components/_share-links.scss +1 -1
  13. data/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav-related.scss +1 -1
  14. data/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav.scss +10 -10
  15. data/app/assets/stylesheets/govuk_publishing_components/components/_table.scss +1 -1
  16. data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_warning-callout.scss +2 -2
  17. data/app/assets/stylesheets/govuk_publishing_components/components/helpers/_markdown-typography.scss +1 -1
  18. data/app/assets/stylesheets/govuk_publishing_components/components/mixins/_grid-helper.scss +1 -1
  19. data/app/models/govuk_publishing_components/audit_applications.rb +1 -1
  20. data/app/models/govuk_publishing_components/component_docs.rb +1 -1
  21. data/app/views/govuk_publishing_components/components/_details.html.erb +18 -2
  22. data/app/views/govuk_publishing_components/components/_image_card.html.erb +11 -11
  23. data/app/views/govuk_publishing_components/components/_layout_footer.html.erb +5 -0
  24. data/app/views/govuk_publishing_components/components/_layout_super_navigation_header.html.erb +7 -3
  25. data/app/views/govuk_publishing_components/components/_metadata.html.erb +1 -5
  26. data/app/views/govuk_publishing_components/components/docs/details.yml +21 -0
  27. data/app/views/govuk_publishing_components/components/docs/image_card.yml +18 -11
  28. data/app/views/govuk_publishing_components/components/feedback/_problem_form.html.erb +5 -1
  29. data/app/views/govuk_publishing_components/components/feedback/_survey_signup_form.html.erb +5 -1
  30. data/lib/govuk_publishing_components/presenters/absolute_links_helper.rb +20 -0
  31. data/lib/govuk_publishing_components/version.rb +1 -1
  32. data/lib/govuk_publishing_components.rb +1 -0
  33. data/node_modules/axe-core/axe.js +604 -440
  34. data/node_modules/axe-core/axe.min.js +2 -2
  35. data/node_modules/axe-core/package.json +1 -1
  36. data/node_modules/axe-core/sri-history.json +4 -0
  37. metadata +5 -3
@@ -7,6 +7,7 @@
7
7
  classes = %w(gem-c-layout-footer govuk-footer)
8
8
  classes << "gem-c-layout-footer--border" if with_border
9
9
  layout_footer_helper = GovukPublishingComponents::Presenters::LayoutFooterHelper.new(navigation, meta)
10
+ absolute_links_helper = GovukPublishingComponents::Presenters::AbsoluteLinksHelper.new()
10
11
  %>
11
12
  <%= tag.footer class: classes, role: "contentinfo", 'data-module': "ga4-link-tracker" do %>
12
13
  <div class="govuk-width-container">
@@ -51,6 +52,8 @@
51
52
  unless attributes[:data][:ga4_link]
52
53
  attributes[:data][:ga4_link] = layout_footer_helper.generate_ga4_link_attribute(index, ga4_section_index, section[:title], index_total)
53
54
  end
55
+
56
+ item[:href] = absolute_links_helper.make_url_absolute(item[:href])
54
57
  %>
55
58
  <%= link_to item[:text], item[:href], attributes %>
56
59
  </li>
@@ -82,6 +85,8 @@
82
85
  unless attributes[:data][:ga4_link]
83
86
  attributes[:data][:ga4_link] = layout_footer_helper.generate_ga4_link_attribute(index, navigation.length, "Support links", index_total)
84
87
  end
88
+
89
+ item[:href] = absolute_links_helper.make_url_absolute(item[:href])
85
90
  %>
86
91
  <%= link_to item[:text], item[:href], attributes %>
87
92
  </li>
@@ -70,6 +70,8 @@
70
70
 
71
71
  popular_links_heading_classes = %w(govuk-heading-m)
72
72
  popular_links_heading_classes << "gem-c-layout-super-navigation-header__popular-links-heading--large-navbar" if large_navbar
73
+
74
+ absolute_links_helper = GovukPublishingComponents::Presenters::AbsoluteLinksHelper.new()
73
75
  %>
74
76
  <%= content_tag("header",
75
77
  {
@@ -311,9 +313,10 @@
311
313
  link_classes = %w[govuk-link gem-c-layout-super-navigation-header__navigation-second-item-link]
312
314
  link_classes << "gem-c-layout-super-navigation-header__navigation-second-item-link--with-description" if has_description
313
315
  tracking_label = column[:label].downcase.gsub(/\s+/, "")
316
+ link_href = absolute_links_helper.make_url_absolute(item[:href])
314
317
  %>
315
318
  <li class="gem-c-layout-super-navigation-header__dropdown-list-item">
316
- <%= link_to item[:label], item[:href], {
319
+ <%= link_to item[:label], link_href, {
317
320
  class: link_classes,
318
321
  data: {
319
322
  track_action: "#{tracking_label}Link",
@@ -360,7 +363,7 @@
360
363
  data-ga4-form='{ "event_name": "search", "type": "header menu bar", "section": "Search GOV.UK", "action": "search", "url": "/search/all" }'
361
364
  data-ga4-form-include-text
362
365
  data-ga4-form-no-answer-undefined
363
- action="/search"
366
+ action="<%= absolute_links_helper.make_url_absolute('/search') %>"
364
367
  method="get"
365
368
  role="search"
366
369
  aria-label="Site-wide"
@@ -394,7 +397,8 @@
394
397
  <% index_total = popular_links.length %>
395
398
  <% popular_links.each_with_index do | popular_link, index | %>
396
399
  <li class="gem-c-layout-super-navigation-header__popular-item">
397
- <%= link_to popular_link[:label], popular_link[:href], {
400
+ <% link_href = absolute_links_helper.make_url_absolute(popular_link[:href]) %>
401
+ <%= link_to popular_link[:label], link_href, {
398
402
  class: [
399
403
  "govuk-link",
400
404
  "gem-c-layout-super-navigation-header__popular-link",
@@ -65,11 +65,7 @@
65
65
  class="gem-c-metadata__definition-link govuk-!-display-none-print js-see-all-updates-link"
66
66
  data-track-category="content-history"
67
67
  data-track-action="see-all-updates-link-clicked"
68
- data-track-label="history"
69
- <% unless disable_ga4 %>
70
- data-module="ga4-link-tracker"
71
- data-ga4-link="<%= ga4_object %>"
72
- <% end%>>
68
+ data-track-label="history">
73
69
  <%= t("components.metadata.see_all_updates") %>
74
70
  </a>
75
71
  <% end %>
@@ -61,6 +61,27 @@ examples:
61
61
  tracking: GTM-123AB
62
62
  block: |
63
63
  We need to know your nationality so we can work out which elections you’re entitled to vote in. If you can’t provide your nationality, you’ll have to send copies of identity documents through the post.
64
+ with_ga4_tracking:
65
+ description: |
66
+ GA4 tracking is mostly handled internally by the component, apart from the required attribute `index_section_count`. This records the number of details components on the page and must be passed by the hosting application. Other GA4 attributes can also be passed if required, including to override attributes set by the component (for some reason this doesn't work in the component guide but works in applications).
67
+
68
+ The tracking automatically includes `index_section` as the index of the component on the page compared with other instances of the component that are also being tracked, e.g. the first details component on a page will be `index_section` 1, the second `index_section` 2, etc.
69
+
70
+ Link tracking for the contents of the details component is not included due to varying tracking requirements. If you need to track links in the component, wrap it in the application with the [GA4 link tracker](https://github.com/alphagov/govuk_publishing_components/blob/main/docs/analytics-ga4/ga4-link-tracker.md).
71
+ data:
72
+ title: What did the ground say to the train?
73
+ ga4_attributes: {
74
+ index_section_count: 6,
75
+ type: "not the default"
76
+ }
77
+ block: |
78
+ Between you and me, I've been tracked.
79
+ disable_ga4_tracking:
80
+ description: Disables GA4 tracking on the component. Tracking is enabled by default.
81
+ data:
82
+ title: No tracking here
83
+ disable_ga4: true
84
+ block: Or here, but thanks for looking.
64
85
  open:
65
86
  data:
66
87
  title: Help with nationality
@@ -12,6 +12,7 @@ accessibility_criteria: |
12
12
  - include alt text for images when present
13
13
  - not have duplicate links for the image and the text
14
14
  - if the contents of the component are in a different language than the rest of the document, include an appropriate `lang` attribute to correctly identify the language used in the component
15
+ uses_component_wrapper_helper: true
15
16
  shared_accessibility_criteria:
16
17
  - link
17
18
  embed: |
@@ -276,6 +277,23 @@ examples:
276
277
  }
277
278
  }
278
279
  ]
280
+ with_ga4_tracking:
281
+ description: The component does not include an option for GA4 tracking, but data attributes to enable the [GA4 link tracker](https://github.com/alphagov/govuk_publishing_components/blob/main/docs/analytics-ga4/ga4-link-tracker.md) can be passed as shown.
282
+ data:
283
+ href: "/not-a-page"
284
+ image_src: "https://assets.publishing.service.gov.uk/government/uploads/system/uploads/feature/image/62756/s300_courts-of-justice.JPG"
285
+ image_alt: "some meaningful alt text please"
286
+ heading_text: "News headline"
287
+ data_attributes:
288
+ module: "ga4-link-tracker"
289
+ ga4_link:
290
+ event_name: "navigation"
291
+ type: "homepage"
292
+ index_section: 1
293
+ index_link: 1
294
+ index_section_count: 1
295
+ index_total: 1
296
+ section: "homepage"
279
297
  with_metadata:
280
298
  description: Can be used for links to people pages to indicate payment type
281
299
  data:
@@ -293,17 +311,6 @@ examples:
293
311
  }
294
312
  ]
295
313
  extra_details_no_indent: true
296
- with_lang:
297
- description: |
298
- Pass through an appropriate `lang` to set a HTML lang attribute for the component.
299
-
300
- The `lang` attribute **must** be set to a [valid BCP47 string](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/lang#Language_tag_syntax). A valid code can be the two or three letter language code - for example, English is `en` or `eng`, Korean is `ko` or `kor` - but if in doubt please check.
301
- data:
302
- href: "/not-a-page"
303
- image_src: "https://assets.publishing.service.gov.uk/government/uploads/system/uploads/feature/image/62756/s300_courts-of-justice.JPG"
304
- image_alt: "some meaningful alt text please"
305
- heading_text: Yr hyn rydym ni'n ei wneud
306
- lang: cy
307
314
  with_sizes_attribute:
308
315
  description: |
309
316
  `sizes` is an attribute that makes use of html's native responsive images functionality.
@@ -1,4 +1,8 @@
1
- <form action="/contact/govuk/problem_reports"
1
+ <%
2
+ absolute_links_helper = GovukPublishingComponents::Presenters::AbsoluteLinksHelper.new()
3
+ %>
4
+
5
+ <form action="<%= absolute_links_helper.make_url_absolute('/contact/govuk/problem_reports') %>"
2
6
  id="something-is-wrong"
3
7
  class="gem-c-feedback__form js-feedback-form"
4
8
  data-track-category="Onsite Feedback"
@@ -1,4 +1,8 @@
1
- <form action="/contact/govuk/email-survey-signup"
1
+ <%
2
+ absolute_links_helper = GovukPublishingComponents::Presenters::AbsoluteLinksHelper.new()
3
+ %>
4
+
5
+ <form action="<%= absolute_links_helper.make_url_absolute('/contact/govuk/email-survey-signup') %>"
2
6
  id="page-is-not-useful"
3
7
  class="gem-c-feedback__form gem-c-feedback__form--email gem-c-feedback__js-show js-feedback-form"
4
8
  data-track-category="yesNoFeedbackForm"
@@ -0,0 +1,20 @@
1
+ module GovukPublishingComponents
2
+ module Presenters
3
+ class AbsoluteLinksHelper
4
+ def make_url_absolute(href)
5
+ # If the URL is already absolute do nothing
6
+ unless href.start_with?("/")
7
+ return href
8
+ end
9
+
10
+ host = ENV["VIRTUAL_HOST"] || Plek.new.website_root
11
+
12
+ unless host.start_with?("http://", "https://", "//")
13
+ host = "//#{host}" # '//' preserves the current protocol, we shouldn't force https as that would break dev environments
14
+ end
15
+
16
+ "#{host}#{href}"
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "37.1.0".freeze
2
+ VERSION = "37.2.0".freeze
3
3
  end
@@ -7,6 +7,7 @@ require "govuk_publishing_components/engine"
7
7
  require "govuk_publishing_components/version"
8
8
  require "govuk_publishing_components/presenters/shared_helper"
9
9
  require "govuk_publishing_components/presenters/component_wrapper_helper"
10
+ require "govuk_publishing_components/presenters/absolute_links_helper"
10
11
  require "govuk_publishing_components/presenters/accordion_helper"
11
12
  require "govuk_publishing_components/presenters/attachment_helper"
12
13
  require "govuk_publishing_components/presenters/big_number_helper"