govuk_publishing_components 23.12.1 → 23.12.2

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: f576e3d439679c36e70503acbdd7b7ae2bed87c9d2dea7a5bbdd11743e8f8161
4
- data.tar.gz: f4b49a21872957da107631f6dc2d0f3ff38d624cde346e2f30ac9f0b4b26e572
3
+ metadata.gz: ee5a24f565f5900b36058d428d5944f205d001d89d4fec819ce73696cab40f92
4
+ data.tar.gz: a3c714fac1eace552f26dabf2da1f357ac0b8a0dc79a7e328f99c748206bcec9
5
5
  SHA512:
6
- metadata.gz: d26821d9c8fc386600981d8173bdd6e7cac6d9a4dc8a03c9c64128dc9ce5c66ecfbfcc079a7e03070dd81d5be4eaf9f9547becbafe148f7de1b1c2f38ee76a52
7
- data.tar.gz: 544cdceba43441a149e1770abeb5074d1a8c40c4d87d023a0d47cd0b42c94a8d142a1a51b7e022293483f5ea9f6f54d64aba2cd63e121c33ea9ee5c6948c4296
6
+ metadata.gz: 6354ef8debf4cab296f119140d6a4018a0484b6c5ef61734a3d4e1920d9e7ea6c0b60219ca14a2275ec0b9d32ae73aae61a9a116218a5eab8651526fd09b9d72
7
+ data.tar.gz: fe69a6990d168343f224155fa7430d22e7f023fab8a9af88ae95f0d08de457bb088c0411e80c85b66e8aef75b5164f2ed5f20e1a5cbc5f350f31a87a8dcf7612
@@ -11,9 +11,12 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
11
11
  this.options = {
12
12
  outOf: 65,
13
13
  applyOnInit: true,
14
- toggleText: 'Toggle between chart and table',
15
14
  autoOutdent: false,
16
15
  outdentAll: false,
16
+ chartVisibleText: 'Change to table and accessible view',
17
+ tableVisibleText: 'Change to chart view',
18
+ chartAlertText: 'Chart visible',
19
+ tableAlertText: 'Table visible',
17
20
  toggleAfter: false, // BOOL set TRUE to append the toggle link
18
21
  returnReference: false // for testing purposes
19
22
  }
@@ -27,6 +30,10 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
27
30
  // store a reference to the table in the object
28
31
  this.$table = $module
29
32
 
33
+ // a container around the graph element so that it can be targeted by screen readers, allowing us to inform screen reader users that the graph isn't accessible
34
+ this.$graphContainer = document.createElement('div')
35
+ this.$graphContainer.className = 'mc-chart-container'
36
+
30
37
  // lets make what will become the new graph
31
38
  this.$graph = document.createElement('div')
32
39
 
@@ -39,6 +46,9 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
39
46
  this.$graph.setAttribute('class', this.$table.className)
40
47
  this.$graph.classList.add('mc-chart')
41
48
 
49
+ // get the id of the current chart within the page so that it can be used during the generation of the toggleLink
50
+ this.chartId = this.getChartId($module)
51
+
42
52
  // set the stacked option based on
43
53
  // giving the table a class of mc-stacked
44
54
  this.options.stacked = this.$table.classList.contains('mc-stacked')
@@ -102,7 +112,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
102
112
  this.addClassesToHeader()
103
113
  this.applyWidths()
104
114
  this.insert()
105
- this.$table.classList.add('visually-hidden')
115
+ this.$table.classList.add('mc-hidden')
106
116
  this.applyOutdent()
107
117
  }
108
118
  }
@@ -164,24 +174,42 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
164
174
  }
165
175
 
166
176
  // construct a link to allow the user to toggle between chart and table
167
- MagnaCharta.prototype.construct.toggleLink = function (toggleText) {
168
- var link = document.createElement('a')
169
- link.setAttribute('href', '#')
170
- link.classList.add('mc-toggle-link')
171
- link.innerHTML = toggleText
172
- link.setAttribute('aria-hidden', 'true')
177
+ MagnaCharta.prototype.construct.toggleLink = function (chartVisibleText) {
178
+ var link = document.createElement('button')
179
+
180
+ // These spans are for managing the content within the button
181
+ // toggleText is the public facing content whilst toggleStatus is visually hidden content that we use to let screen reader users know that the toggle link has been clicked
182
+ var toggleText = document.createElement('span')
183
+ var toggleStatus = document.createElement('span')
184
+
185
+ toggleText.classList.add('mc-toggle-text')
186
+ toggleText.innerHTML = chartVisibleText
187
+
188
+ toggleStatus.classList.add('govuk-visually-hidden', 'mc-toggle-status')
189
+ toggleStatus.setAttribute('role', 'alert')
190
+
191
+ link.classList.add('mc-toggle-button')
192
+ link.appendChild(toggleText)
193
+ link.appendChild(toggleStatus)
173
194
 
174
195
  return link
175
196
  }
176
197
 
177
198
  // toggles between showing the table and showing the chart
178
- MagnaCharta.prototype.addToggleClick = function () {
199
+ MagnaCharta.prototype.addToggleClick = function (chartVisible, tableVisible, chartAlert, tableAlert) {
179
200
  var that = this
180
201
 
181
202
  this.toggleLink.addEventListener('click', function (e) {
182
203
  e.preventDefault()
183
- that.$graph.classList.toggle('visually-hidden')
184
- that.$table.classList.toggle('visually-hidden')
204
+
205
+ var toggleText = that.toggleLink.querySelector('.mc-toggle-text')
206
+ var toggleStatus = that.toggleLink.querySelector('.mc-toggle-status')
207
+
208
+ that.$graphContainer.classList.toggle('mc-hidden')
209
+ that.$table.classList.toggle('mc-hidden')
210
+
211
+ toggleText.innerHTML = toggleText.innerHTML === tableVisible ? chartVisible : tableVisible
212
+ toggleStatus.innerHTML = toggleStatus.innerHTML === tableAlert ? chartAlert : tableAlert
185
213
  })
186
214
  }
187
215
 
@@ -191,8 +219,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
191
219
  // get at options and properties
192
220
  var thead = this.construct.thead.call(this)
193
221
  var tbody = this.construct.tbody.call(this)
194
- this.toggleLink = this.construct.toggleLink(this.options.toggleText)
195
- this.addToggleClick(this.toggleLink)
222
+ this.toggleLink = this.construct.toggleLink(this.options.chartVisibleText)
223
+ this.addToggleClick(this.options.chartVisibleText, this.options.tableVisibleText, this.options.chartAlertText, this.options.tableAlertText)
196
224
 
197
225
  if (this.options.hasCaption) {
198
226
  var caption = this.construct.caption.call(this)
@@ -379,7 +407,18 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
379
407
  }
380
408
 
381
409
  MagnaCharta.prototype.insert = function () {
382
- this.$table.insertAdjacentElement('afterend', this.$graph)
410
+ var label = document.createElement('span')
411
+ var labelId = 'mc-chart-not-accessible-' + this.chartId
412
+
413
+ label.innerHTML = 'This content is not accessible - switch to table'
414
+ label.className = 'mc-hidden'
415
+ label.id = labelId
416
+
417
+ this.$graphContainer.setAttribute('aria-labelledby', labelId)
418
+ this.$graphContainer.appendChild(this.$graph)
419
+ this.$graphContainer.appendChild(label)
420
+
421
+ this.$table.insertAdjacentElement('afterend', this.$graphContainer)
383
422
  }
384
423
 
385
424
  MagnaCharta.prototype.applyOutdent = function () {
@@ -419,5 +458,18 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
419
458
  }
420
459
  }
421
460
 
461
+ MagnaCharta.prototype.getChartId = function (module) {
462
+ var allCharts = document.querySelectorAll('table.js-barchart-table')
463
+ var id = null
464
+
465
+ allCharts.forEach(function (chart, i) {
466
+ if (chart === module) {
467
+ id = i
468
+ }
469
+ })
470
+
471
+ return id
472
+ }
473
+
422
474
  Modules.MagnaCharta = MagnaCharta
423
475
  })(window.GOVUK.Modules)
@@ -14,6 +14,10 @@
14
14
  &:focus {
15
15
  z-index: 1;
16
16
  }
17
+
18
+ &::-ms-reveal {
19
+ display: none;
20
+ }
17
21
  }
18
22
  }
19
23
 
@@ -270,15 +270,26 @@
270
270
  text-align: left;
271
271
  }
272
272
 
273
- .mc-toggle-link {
274
- display: block;
275
- margin-top: 30px;
273
+ .mc-toggle-button {
274
+ @extend %govuk-body-s;
275
+ border: 1px solid $govuk-border-colour;
276
+ color: $govuk-link-colour;
277
+ cursor: pointer;
278
+ margin: govuk-spacing(0);
279
+ padding: govuk-spacing(2);
280
+ background-color: govuk-colour("white");
281
+
282
+ &:focus {
283
+ @include govuk-focused-text;
284
+ background-color: $govuk-focus-colour;
285
+ border-color: transparent;
286
+ }
276
287
  }
277
288
 
278
289
  // Hides the original table
279
- .visually-hidden,
280
- .visually-hidden caption {
281
- @include govuk-visually-hidden;
290
+ .mc-hidden,
291
+ .mc-hidden caption {
292
+ display: none;
282
293
 
283
294
  // It's reapplied to captions because Firefox can't hide
284
295
  // table captions unless it's applied directly to it. Go figure.
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "23.12.1".freeze
2
+ VERSION = "23.12.2".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: 23.12.1
4
+ version: 23.12.2
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: 2021-01-08 00:00:00.000000000 Z
11
+ date: 2021-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_app_config