govuk_publishing_components 57.2.0 → 57.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc35380bef3675b6001b4827358013c9c54218a696fbe7170625d5c0c9f33bdd
4
- data.tar.gz: 77f96614f15a6e7978e3265bf3f3275e25826f7cd3a629cc90bbb55cb2675c30
3
+ metadata.gz: 41a446b912bf0ceb75ba5700eeff0f6d91b976039d175fe9262e44ed75fbd420
4
+ data.tar.gz: 18c75d217261b9b6793f251cc2020fa785da20f31aa47ada9721dbb642a4ccb8
5
5
  SHA512:
6
- metadata.gz: 765da3cf1fb7d292acb42f840bc373166360790f30cb869334629750042fe0e7869ff310115e21019757f8bce65f5b3ad6e2ecaca1ac5f06d39f93592370d4ac
7
- data.tar.gz: fe864e55147fd9faf3986d951c5af9b91d96c218563b2a1a080fb742c14ed0aca1dddc3ec01e281259a32e628cc0745644c54ab7ed558c87e62066c44818d582
6
+ metadata.gz: d3ee818d7df8773727db46921ba33a905de236ed76b4a3c00d5aad2394cf26513fbc6a1039926e7ac29466ec98d1e25b98701d49cfcd10e7c663abb1f23aaaf9
7
+ data.tar.gz: 46bb83df7af008ed114877f485b4888789c1e72b7876692c10a025e631df2391a99ee4c631e5d5ec3325c3a517d8cda520e20fd4c2832d6dc0d900e75577afcd
@@ -150,8 +150,8 @@ window.GOVUK.analyticsGa4.analyticsModules = window.GOVUK.analyticsGa4.analytics
150
150
  For example, .csv/preview or .mp4/preview will be matched.
151
151
  Regex is used over JS string methods as this should work with anchor links, query string parameters and files that may have 'preview' in their name.
152
152
  */
153
- var previewRegex = /\.\w+\/preview/i
154
- return previewRegex.test(href) || href.startsWith('https://www.gov.uk/csv-preview/')
153
+ var previewRegex = /\.\w+\/preview|(\/csv-preview\/)/i
154
+ return previewRegex.test(href)
155
155
  },
156
156
 
157
157
  hrefPointsToDownloadPath: function (href) {
@@ -25,8 +25,9 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
25
25
 
26
26
  if (eventData) {
27
27
  item.dataset.ga4Event = eventData.dataset.ga4Event
28
+ item.dataset.indexSection = event.oldIndex
28
29
  item.dataset.action = 'drag and drop'
29
- item.dataset.text = event.newIndex > event.oldIndex ? 'Up' : 'Down'
30
+ item.dataset.text = event.newIndex > event.oldIndex ? 'Down' : 'Up'
30
31
  this.triggerEvent(item, 'click')
31
32
  delete item.dataset.ga4Event
32
33
  }
@@ -20,7 +20,7 @@
20
20
  }
21
21
 
22
22
  YoutubeLinkEnhancement.prototype.paragraphHasOtherContent = function (paragraph, link) {
23
- return paragraph.innerHTML.replaceAll(this.punctuationRegex, '') !== link.outerHTML.replaceAll(this.punctuationRegex, '')
23
+ return paragraph.innerHTML.replaceAll(this.punctuationRegex, '').trim() !== link.outerHTML.replaceAll(this.punctuationRegex, '').trim()
24
24
  }
25
25
 
26
26
  YoutubeLinkEnhancement.prototype.decorateLink = function () {
@@ -222,6 +222,17 @@
222
222
  }
223
223
  }
224
224
 
225
+ YoutubeLinkEnhancement.sanitiseVideoId = function (pathname) {
226
+ // YouTube links can now contain an ?si= param in the URL.
227
+ // This usually only appears on youtu.be links but it's appearing for us on youtube.com URLs due to some Whitehall regex being outdated.
228
+ // Therefore we need to use regex to remove it from the path.
229
+ // E.g. youtube.com/watch?v=[video-id]?si=ABCzJtVWBAZ2o_l3
230
+ // ?=si in this case isn't a valid query parameter as it isn't using an &, so we can't use JS' native URL API to filter it out.
231
+ if (pathname) {
232
+ return pathname.replace(/(\?|&)(.+)=.+/g, '')
233
+ }
234
+ }
235
+
225
236
  // This is a public class method so it can be used outside of this embed to
226
237
  // check that user input for videos will be supported in govspeak
227
238
  YoutubeLinkEnhancement.parseVideoId = function (url) {
@@ -232,9 +243,10 @@
232
243
  } catch (e) { return undefined }
233
244
 
234
245
  if (u.host === 'www.youtube.com' || u.host === 'youtube.com') {
235
- return u.searchParams.get('v') || undefined
246
+ return this.sanitiseVideoId(u.searchParams.get('v')) || undefined
236
247
  } else if (u.host === 'youtu.be') {
237
- return u.pathname.slice(1) // Trim the leading /
248
+ var pathName = u.pathname.slice(1) // Trim the leading /
249
+ return this.sanitiseVideoId(pathName)
238
250
  }
239
251
  }
240
252
 
@@ -6,7 +6,6 @@ module GovukPublishingComponents
6
6
  if gem_data[:gem_found]
7
7
  @applications_using_static = %w[
8
8
  collections
9
- feedback
10
9
  finder-frontend
11
10
  frontend
12
11
  government-frontend
@@ -7,12 +7,16 @@
7
7
  name ||= id
8
8
  is_page_heading ||= false
9
9
  data_attributes ||= {}
10
+ aria_controls ||= nil
10
11
 
11
12
  shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)
12
13
  heading_size = false unless shared_helper.valid_heading_size?(heading_size)
13
14
  select_helper = GovukPublishingComponents::Presenters::SelectHelper.new(local_assigns)
14
15
 
15
- aria_describedby = { describedby: select_helper.describedby }
16
+ aria_attributes = {
17
+ controls: aria_controls,
18
+ describedby: select_helper.describedby
19
+ }
16
20
  %>
17
21
  <% if select_helper.options.any? && id && label %>
18
22
  <%= content_tag :div, class: select_helper.css_classes do %>
@@ -40,6 +44,6 @@
40
44
  } %>
41
45
  <% end %>
42
46
 
43
- <%= select_tag name, options_for_select(select_helper.option_markup, select_helper.selected_option), id: id, class: select_helper.select_classes, aria: aria_describedby, data: data_attributes %>
47
+ <%= select_tag name, options_for_select(select_helper.option_markup, select_helper.selected_option), id: id, class: select_helper.select_classes, aria: aria_attributes, data: data_attributes %>
44
48
  <% end %>
45
49
  <% end %>
@@ -150,7 +150,7 @@ examples:
150
150
  url: '/government/organisations/hm-prison-service'
151
151
  brand: 'ministry-of-justice'
152
152
  image:
153
- url: 'https://assets.publishing.service.gov.uk/government/uploads/system/uploads/organisation/logo/321/HMPS.jpg'
153
+ url: 'https://assets.publishing.service.gov.uk/media/6850134301d3b0e7b62da740/hmps_25_gov_240x188.png'
154
154
  alt_text: 'HM Prison Service'
155
155
  without_a_link:
156
156
  data:
@@ -42,6 +42,19 @@ examples:
42
42
  selected: true
43
43
  - text: Option three
44
44
  value: option3
45
+ with_disabled_options:
46
+ description: Options can be disabled using the `disabled` parameter. Note that it is possible to have an option that is both disabled and selected.
47
+ data:
48
+ id: dropdown2-0
49
+ label: Option 3 disabled
50
+ options:
51
+ - text: Option one
52
+ value: option1
53
+ - text: Option two
54
+ value: option2
55
+ - text: Option three
56
+ value: option3
57
+ disabled: true
45
58
  with_hint:
46
59
  description: When a hint is included the `aria-describedby` attribute of the select is included to point to the hint. When an error and a hint are present, that attribute includes the IDs of both the hint and the error.
47
60
  data:
@@ -54,6 +67,18 @@ examples:
54
67
  value: option1
55
68
  - text: Something else
56
69
  value: option2
70
+ with_aria_controls:
71
+ data:
72
+ id: dropdown4-4
73
+ label: My Dropdown
74
+ aria_controls: dropdown4-3
75
+ options:
76
+ - text: Option one
77
+ value: option1
78
+ - text: Option two
79
+ value: option2
80
+ - text: Option three
81
+ value: option3
57
82
  with_data_attributes:
58
83
  description: Data attributes can be passed to the select component if needed.
59
84
  data:
@@ -44,13 +44,15 @@ module GovukPublishingComponents
44
44
  [
45
45
  option[:text],
46
46
  option[:value],
47
- options_data_attribute(option[:data_attributes]),
47
+ options_extra_attributes(option[:data_attributes], option[:disabled]),
48
48
  ]
49
49
  end
50
50
  end
51
51
 
52
- def options_data_attribute(attributes)
53
- return {} if attributes.nil?
52
+ def options_extra_attributes(attributes, disabled)
53
+ attrs = {}
54
+ attrs[:disabled] = true if disabled
55
+ return attrs if attributes.nil?
54
56
 
55
57
  attrs = {}
56
58
  attributes.each do |key, value|
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "57.2.0".freeze
2
+ VERSION = "57.3.1".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_publishing_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 57.2.0
4
+ version: 57.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev