govuk_publishing_components 37.6.1 → 37.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 057a27088f3e56f3de0b207bf272737059e084e11f7ad5d60c9c64f51b36f36c
4
- data.tar.gz: 2e7c53dbecff6dcb761c8b181be7c22a051d1e67738f96d6386cc24b08e4a850
3
+ metadata.gz: 53bea50d5b775c3e29b495eb9098ceb4d4708f081a7e0d3f6c18069de3f4e82b
4
+ data.tar.gz: dff2018e3a0320a9bb5f0822ec6145c656d9c4b8afee95a07173fc76f48c337e
5
5
  SHA512:
6
- metadata.gz: 853e1a7952502815cc9cf864feedb258266b06f402c37d8622ce3e2a8550b160bfc676e60221b5e6a0332adca201bc7a8b651d3cee2ff451f9ade26c61a74304
7
- data.tar.gz: 54df263cbc3fe4b0a4bf2b7f8e3207e5d0292fb6dd79fddfe87cdcea0b844d0c5b4a73527de5ef7d747991e505af18b25228c8644d6c973a5431fb993707a3f7
6
+ metadata.gz: 810afe26d85390892172d9424293c9b2937d6c39531470b680428929852ba512d9e2eb738286fdce53fbf1e55b84c7eab0a1119e3f41661771d429366cf83a49
7
+ data.tar.gz: aabf6aa8ee19cbbe2c86ecc666a86be58218a0bf5c61e5834cbd93741ad83ceb78458c1b3dd6f4dfccb74179743f7bcda67f1e75613c6807641cbe6654fab7a8
@@ -40,11 +40,33 @@ window.GOVUK.analyticsGa4.analyticsModules = window.GOVUK.analyticsGa4.analytics
40
40
  return
41
41
  }
42
42
 
43
- // don't track this link if it's already being tracked by the another tracker (e.g. the link tracker or ecommerce tracker)
44
- if (element.closest('[data-ga4-link]') || element.closest('[data-ga4-ecommerce-path]')) {
43
+ // Don't track this link if it's already being tracked by the ecommerce tracker
44
+ if (element.closest('[data-ga4-ecommerce-path]')) {
45
45
  return
46
46
  }
47
47
 
48
+ // Code below ensures the tracker plays nicely with the other link tracker
49
+ var otherLinkTracker = element.closest('[data-ga4-link]')
50
+ if (otherLinkTracker) {
51
+ var limitToElementClass = otherLinkTracker.getAttribute('data-ga4-limit-to-element-class')
52
+
53
+ if (!limitToElementClass) {
54
+ // If this link is inside the other link tracker, and the other link tracker IS NOT limiting itself to specific classes,
55
+ // then stop this tracker from firing, as the other tracker is responsible for this link.
56
+ return
57
+ } else {
58
+ // If this link is inside the other link tracker, but the other link tracker IS limiting itself to specific classes,
59
+ // then track the link here only if it is not within the specified classes that the other tracker is looking for.
60
+ var classes = limitToElementClass.split(',')
61
+
62
+ for (var i = 0; i < classes.length; i++) {
63
+ if (element.closest('.' + classes[i].trim())) {
64
+ return
65
+ }
66
+ }
67
+ }
68
+ }
69
+
48
70
  var href = element.getAttribute('href')
49
71
 
50
72
  if (!href) {
@@ -93,6 +93,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
93
93
  this.$module = $module
94
94
  this.$searchToggle = this.$module.querySelector('#super-search-menu-toggle')
95
95
  this.$searchMenu = this.$module.querySelector('#super-search-menu')
96
+ this.$navToggle = this.$module.querySelector('#super-navigation-menu-toggle')
97
+ this.$navMenu = this.$module.querySelector('#super-navigation-menu')
96
98
 
97
99
  // The menu toggler buttons need three attributes for this to work:
98
100
  // - `aria-controls` contains the id of the menu to be toggled
@@ -126,7 +128,68 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
126
128
  toggle($target, $targetMenu)
127
129
  }
128
130
 
131
+ SuperNavigationMegaMenu.prototype.handleKeyDown = function (event) {
132
+ var KEY_TAB = 9
133
+ var KEY_ESC = 27
134
+ var $navMenuLinks = this.$navMenu.querySelectorAll('li a')
135
+ var $firstNavLink = $navMenuLinks[0]
136
+ var $lastNavLink = $navMenuLinks[$navMenuLinks.length - 1]
137
+ var $searchMenuLinks = this.$searchMenu.querySelectorAll('li a')
138
+ var $lastSearchLink = $searchMenuLinks[$searchMenuLinks.length - 1]
139
+
140
+ if (event.keyCode === KEY_TAB) {
141
+ if (!this.$navMenu.hasAttribute('hidden')) {
142
+ switch (document.activeElement) {
143
+ case this.$navToggle:
144
+ if (!event.shiftKey) {
145
+ event.preventDefault()
146
+ $firstNavLink.focus()
147
+ }
148
+ break
149
+ case $lastNavLink:
150
+ if (!event.shiftKey) {
151
+ event.preventDefault()
152
+ this.$searchToggle.focus()
153
+ hide(this.$navToggle, this.$navMenu)
154
+ }
155
+ break
156
+ case $firstNavLink:
157
+ if (event.shiftKey) {
158
+ event.preventDefault()
159
+ this.$navToggle.focus()
160
+ }
161
+ break
162
+ case this.$searchToggle:
163
+ if (event.shiftKey) {
164
+ event.preventDefault()
165
+ $lastNavLink.focus()
166
+ }
167
+ break
168
+ default:
169
+ break
170
+ }
171
+ } else if (!this.$searchMenu.hasAttribute('hidden')) {
172
+ if (document.activeElement === $lastSearchLink) {
173
+ if (!event.shiftKey) {
174
+ hide(this.$searchToggle, this.$searchMenu)
175
+ }
176
+ }
177
+ }
178
+ } else if (event.keyCode === KEY_ESC) {
179
+ if (!this.$navMenu.hasAttribute('hidden')) {
180
+ hide(this.$navToggle, this.$navMenu)
181
+ this.$navToggle.focus()
182
+ } else if (!this.$searchMenu.hasAttribute('hidden')) {
183
+ hide(this.$searchToggle, this.$searchMenu)
184
+ this.$searchToggle.focus()
185
+ }
186
+ }
187
+ }
188
+
129
189
  SuperNavigationMegaMenu.prototype.init = function () {
190
+ // Handle key events for tab and escape keys
191
+ this.$module.addEventListener('keydown', this.handleKeyDown.bind(this))
192
+
130
193
  for (var j = 0; j < this.$buttons.length; j++) {
131
194
  var $button = this.$buttons[j]
132
195
  $button.addEventListener('click', this.buttonHandler.bind(this), true)
@@ -27,6 +27,10 @@
27
27
  event.keyCode = keyCode
28
28
  }
29
29
 
30
+ if (params.shiftKey) {
31
+ event.shiftKey = true
32
+ }
33
+
30
34
  element.dispatchEvent(event)
31
35
  }
32
36
  }(window))
@@ -10,9 +10,20 @@
10
10
  classes << "disable-youtube" if disable_youtube_expansions
11
11
  classes << "gem-c-govspeak--inverse" if inverse
12
12
 
13
+ disable_ga4 ||= false
14
+
13
15
  data_modules = "govspeak"
16
+ data_modules << " ga4-link-tracker" unless disable_ga4
14
17
  data_attributes = { module: data_modules }
15
18
 
19
+ unless disable_ga4
20
+ data_attributes.merge!({
21
+ ga4_track_links_only: "",
22
+ ga4_limit_to_element_class: "call-to-action, info-notice, help-notice, advisory",
23
+ ga4_link: { "event_name": "navigation", "type": "callout" }.to_json,
24
+ })
25
+ end
26
+
16
27
  %>
17
28
 
18
29
  <%= tag.div(class: "gem-c-govspeak govuk-govspeak " + classes.join(" "), data: data_attributes) do %>
@@ -162,7 +162,6 @@
162
162
 
163
163
  <%
164
164
  link = t("components.layout_super_navigation_header.navigation_link")
165
- unique_id = SecureRandom.hex(4)
166
165
  show_menu_text = show_navigation_menu_text
167
166
  hide_menu_text = hide_navigation_menu_text
168
167
  tracking_label = link[:label].downcase.gsub(/\s+/, "")
@@ -192,7 +191,7 @@
192
191
 
193
192
  <%= content_tag(:button, {
194
193
  aria: {
195
- controls: "super-navigation-menu-#{unique_id}",
194
+ controls: "super-navigation-menu",
196
195
  expanded: false,
197
196
  label: show_menu_text,
198
197
  },
@@ -213,7 +212,7 @@
213
212
  }
214
213
  },
215
214
  hidden: true,
216
- id: "super-navigation-menu-#{unique_id}-toggle",
215
+ id: "super-navigation-menu-toggle",
217
216
  type: "button",
218
217
  }) do %>
219
218
  <%= tag.span link[:label], class: top_toggle_button_inner_classes %>
@@ -282,7 +281,7 @@
282
281
  </div>
283
282
 
284
283
  <%= content_tag(:div, {
285
- id: "super-navigation-menu-#{unique_id}",
284
+ id: "super-navigation-menu",
286
285
  hidden: "",
287
286
  class: dropdown_menu_classes,
288
287
  }) do %>
@@ -914,3 +914,12 @@ examples:
914
914
  <p>Deforested area. Credit: Blue Ventures-Garth Cripps</p>
915
915
  </figcaption>
916
916
  </figure>
917
+ without_ga4_tracking:
918
+ description: |
919
+ Disables GA4 tracking on the component. Tracking is enabled by default. This adds a data module and data-attributes with JSON data. See the [ga4-link-tracker documentation](https://github.com/alphagov/govuk_publishing_components/blob/main/docs/analytics-ga4/ga4-link-tracker.md) for more information.
920
+ data:
921
+ block: |
922
+ <p>
923
+ <a href='https://www.gov.uk'>Hello World</a>
924
+ </p>
925
+ disable_ga4: true
@@ -7,6 +7,8 @@ accessibility_criteria: |
7
7
  The component must:
8
8
 
9
9
  * have a text contrast ratio higher than 4.5:1 against the background colour to meet WCAG AA
10
+ * follow the expected tabbing border
11
+ * allow menus to be closed when the escape key is pressed
10
12
 
11
13
  Images in the super navigation header must:
12
14
 
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "37.6.1".freeze
2
+ VERSION = "37.7.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_publishing_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 37.6.1
4
+ version: 37.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-11 00:00:00.000000000 Z
11
+ date: 2024-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_app_config