govuk_publishing_components 21.60.0 → 21.62.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/govuk_publishing_components/components/checkboxes.js +102 -73
  3. data/app/assets/javascripts/govuk_publishing_components/ie.js +2 -0
  4. data/app/assets/javascripts/govuk_publishing_components/lib/govspeak/youtube-link-enhancement.js +1 -1
  5. data/app/assets/javascripts/govuk_publishing_components/vendor/html5shiv-printshiv.js +4 -0
  6. data/app/assets/javascripts/govuk_publishing_components/vendor/json2.js +487 -0
  7. data/app/assets/stylesheets/component_guide/application.scss +4 -0
  8. data/app/assets/stylesheets/govuk_publishing_components/_all_components.scss +1 -0
  9. data/app/assets/stylesheets/govuk_publishing_components/components/_layout-footer.scss +8 -0
  10. data/app/assets/stylesheets/govuk_publishing_components/components/_layout-for-public.scss +4 -0
  11. data/app/assets/stylesheets/govuk_publishing_components/components/_layout-header.scss +87 -1
  12. data/app/assets/stylesheets/govuk_publishing_components/components/_radio.scss +1 -1
  13. data/app/assets/stylesheets/govuk_publishing_components/components/_search.scss +46 -0
  14. data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_charts.scss +4 -2
  15. data/app/assets/stylesheets/govuk_publishing_components/govuk_frontend_support.scss +8 -0
  16. data/app/models/govuk_publishing_components/audit_applications.rb +35 -23
  17. data/app/models/govuk_publishing_components/audit_comparer.rb +13 -0
  18. data/app/models/govuk_publishing_components/audit_components.rb +1 -1
  19. data/app/models/govuk_publishing_components/component_example.rb +4 -0
  20. data/app/views/govuk_publishing_components/audit/show.html.erb +32 -3
  21. data/app/views/govuk_publishing_components/component_guide/component_doc/_component.html.erb +1 -0
  22. data/app/views/govuk_publishing_components/components/_image_card.html.erb +1 -1
  23. data/app/views/govuk_publishing_components/components/_layout_footer.html.erb +32 -21
  24. data/app/views/govuk_publishing_components/components/_layout_for_public.html.erb +76 -0
  25. data/app/views/govuk_publishing_components/components/_layout_header.html.erb +39 -51
  26. data/app/views/govuk_publishing_components/components/_search.html.erb +10 -5
  27. data/app/views/govuk_publishing_components/components/_share_links.html.erb +9 -9
  28. data/app/views/govuk_publishing_components/components/docs/govspeak.yml +45 -0
  29. data/app/views/govuk_publishing_components/components/docs/image_card.yml +13 -1
  30. data/app/views/govuk_publishing_components/components/docs/layout_footer.yml +17 -0
  31. data/app/views/govuk_publishing_components/components/docs/layout_for_admin.yml +5 -1
  32. data/app/views/govuk_publishing_components/components/docs/layout_for_public.yml +29 -0
  33. data/app/views/govuk_publishing_components/components/docs/layout_header.yml +34 -0
  34. data/app/views/govuk_publishing_components/components/docs/search.yml +6 -0
  35. data/app/views/govuk_publishing_components/components/layout_header/_header_logo.html.erb +23 -0
  36. data/app/views/govuk_publishing_components/components/layout_header/_navigation_items.html.erb +17 -0
  37. data/app/views/govuk_publishing_components/components/layout_header/_search.html.erb +9 -0
  38. data/config/initializers/assets.rb +8 -0
  39. data/lib/govuk_publishing_components.rb +1 -0
  40. data/lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_priority.rb +1 -0
  41. data/lib/govuk_publishing_components/presenters/image_card_helper.rb +3 -2
  42. data/lib/govuk_publishing_components/presenters/public_layout_helper.rb +380 -0
  43. data/lib/govuk_publishing_components/version.rb +1 -1
  44. data/node_modules/govuk-frontend/govuk/all.js +160 -57
  45. data/node_modules/govuk-frontend/govuk/components/character-count/_index.scss +0 -4
  46. data/node_modules/govuk-frontend/govuk/components/character-count/character-count.js +16 -8
  47. data/node_modules/govuk-frontend/govuk/components/character-count/macro-options.json +6 -0
  48. data/node_modules/govuk-frontend/govuk/components/character-count/template.njk +1 -0
  49. data/node_modules/govuk-frontend/govuk/components/checkboxes/_index.scss +6 -5
  50. data/node_modules/govuk-frontend/govuk/components/checkboxes/checkboxes.js +68 -21
  51. data/node_modules/govuk-frontend/govuk/components/date-input/macro-options.json +1 -1
  52. data/node_modules/govuk-frontend/govuk/components/file-upload/_index.scss +0 -27
  53. data/node_modules/govuk-frontend/govuk/components/footer/_index.scss +0 -3
  54. data/node_modules/govuk-frontend/govuk/components/footer/template.njk +1 -1
  55. data/node_modules/govuk-frontend/govuk/components/header/template.njk +1 -1
  56. data/node_modules/govuk-frontend/govuk/components/hint/_index.scss +2 -2
  57. data/node_modules/govuk-frontend/govuk/components/hint/template.njk +2 -2
  58. data/node_modules/govuk-frontend/govuk/components/input/_index.scss +0 -3
  59. data/node_modules/govuk-frontend/govuk/components/input/macro-options.json +6 -0
  60. data/node_modules/govuk-frontend/govuk/components/input/template.njk +1 -0
  61. data/node_modules/govuk-frontend/govuk/components/radios/radios.js +76 -28
  62. data/node_modules/govuk-frontend/govuk/components/select/_index.scss +0 -3
  63. data/node_modules/govuk-frontend/govuk/components/skip-link/_index.scss +1 -0
  64. data/node_modules/govuk-frontend/govuk/components/textarea/_index.scss +0 -3
  65. data/node_modules/govuk-frontend/govuk/components/textarea/macro-options.json +6 -0
  66. data/node_modules/govuk-frontend/govuk/components/textarea/template.njk +1 -0
  67. data/node_modules/govuk-frontend/govuk/components/warning-text/_index.scss +4 -2
  68. data/node_modules/govuk-frontend/govuk/helpers/_colour.scss +1 -1
  69. data/node_modules/govuk-frontend/govuk/settings/_colours-applied.scss +2 -2
  70. data/node_modules/govuk-frontend/govuk/settings/_colours-palette.scss +33 -33
  71. data/node_modules/govuk-frontend/govuk/settings/_measurements.scss +4 -1
  72. data/node_modules/govuk-frontend/package.json +1 -1
  73. metadata +12 -2
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "21.60.0".freeze
2
+ VERSION = "21.62.0".freeze
3
3
  end
@@ -1542,13 +1542,22 @@ CharacterCount.prototype.init = function () {
1542
1542
  // Remove hard limit if set
1543
1543
  $module.removeAttribute('maxlength');
1544
1544
 
1545
- // Bind event changes to the textarea
1546
- var boundChangeEvents = this.bindChangeEvents.bind(this);
1547
- boundChangeEvents();
1545
+ // When the page is restored after navigating 'back' in some browsers the
1546
+ // state of the character count is not restored until *after* the DOMContentLoaded
1547
+ // event is fired, so we need to sync after the pageshow event in browsers
1548
+ // that support it.
1549
+ if ('onpageshow' in window) {
1550
+ window.addEventListener('pageshow', this.sync.bind(this));
1551
+ } else {
1552
+ window.addEventListener('DOMContentLoaded', this.sync.bind(this));
1553
+ }
1554
+
1555
+ this.sync();
1556
+ };
1548
1557
 
1549
- // Update count message
1550
- var boundUpdateCountMessage = this.updateCountMessage.bind(this);
1551
- boundUpdateCountMessage();
1558
+ CharacterCount.prototype.sync = function () {
1559
+ this.bindChangeEvents();
1560
+ this.updateCountMessage();
1552
1561
  };
1553
1562
 
1554
1563
  // Read data attributes
@@ -1596,8 +1605,7 @@ CharacterCount.prototype.checkIfValueChanged = function () {
1596
1605
  if (!this.$textarea.oldValue) this.$textarea.oldValue = '';
1597
1606
  if (this.$textarea.value !== this.$textarea.oldValue) {
1598
1607
  this.$textarea.oldValue = this.$textarea.value;
1599
- var boundUpdateCountMessage = this.updateCountMessage.bind(this);
1600
- boundUpdateCountMessage();
1608
+ this.updateCountMessage();
1601
1609
  }
1602
1610
  };
1603
1611
 
@@ -1666,44 +1674,91 @@ function Checkboxes ($module) {
1666
1674
  this.$inputs = $module.querySelectorAll('input[type="checkbox"]');
1667
1675
  }
1668
1676
 
1677
+ /**
1678
+ * Initialise Checkboxes
1679
+ *
1680
+ * Checkboxes can be associated with a 'conditionally revealed' content block –
1681
+ * for example, a checkbox for 'Phone' could reveal an additional form field for
1682
+ * the user to enter their phone number.
1683
+ *
1684
+ * These associations are made using a `data-aria-controls` attribute, which is
1685
+ * promoted to an aria-controls attribute during initialisation.
1686
+ *
1687
+ * We also need to restore the state of any conditional reveals on the page (for
1688
+ * example if the user has navigated back), and set up event handlers to keep
1689
+ * the reveal in sync with the checkbox state.
1690
+ */
1669
1691
  Checkboxes.prototype.init = function () {
1670
1692
  var $module = this.$module;
1671
1693
  var $inputs = this.$inputs;
1672
1694
 
1673
- /**
1674
- * Loop over all items with [data-controls]
1675
- * Check if they have a matching conditional reveal
1676
- * If they do, assign attributes.
1677
- **/
1678
1695
  nodeListForEach($inputs, function ($input) {
1679
- var controls = $input.getAttribute('data-aria-controls');
1696
+ var target = $input.getAttribute('data-aria-controls');
1680
1697
 
1681
- // Check if input controls anything
1682
- // Check if content exists, before setting attributes.
1683
- if (!controls || !$module.querySelector('#' + controls)) {
1698
+ // Skip checkboxes without data-aria-controls attributes, or where the
1699
+ // target element does not exist.
1700
+ if (!target || !$module.querySelector('#' + target)) {
1684
1701
  return
1685
1702
  }
1686
1703
 
1687
- // If we have content that is controlled, set attributes.
1688
- $input.setAttribute('aria-controls', controls);
1704
+ // Promote the data-aria-controls attribute to a aria-controls attribute
1705
+ // so that the relationship is exposed in the AOM
1706
+ $input.setAttribute('aria-controls', target);
1689
1707
  $input.removeAttribute('data-aria-controls');
1690
- this.setAttributes($input);
1691
- }.bind(this));
1708
+ });
1709
+
1710
+ // When the page is restored after navigating 'back' in some browsers the
1711
+ // state of form controls is not restored until *after* the DOMContentLoaded
1712
+ // event is fired, so we need to sync after the pageshow event in browsers
1713
+ // that support it.
1714
+ if ('onpageshow' in window) {
1715
+ window.addEventListener('pageshow', this.syncAllConditionalReveals.bind(this));
1716
+ } else {
1717
+ window.addEventListener('DOMContentLoaded', this.syncAllConditionalReveals.bind(this));
1718
+ }
1719
+
1720
+ // Although we've set up handlers to sync state on the pageshow or
1721
+ // DOMContentLoaded event, init could be called after those events have fired,
1722
+ // for example if they are added to the page dynamically, so sync now too.
1723
+ this.syncAllConditionalReveals();
1692
1724
 
1693
- // Handle events
1694
1725
  $module.addEventListener('click', this.handleClick.bind(this));
1695
1726
  };
1696
1727
 
1697
- Checkboxes.prototype.setAttributes = function ($input) {
1698
- var inputIsChecked = $input.checked;
1699
- $input.setAttribute('aria-expanded', inputIsChecked);
1728
+ /**
1729
+ * Sync the conditional reveal states for all inputs in this $module.
1730
+ */
1731
+ Checkboxes.prototype.syncAllConditionalReveals = function () {
1732
+ nodeListForEach(this.$inputs, this.syncConditionalRevealWithInputState.bind(this));
1733
+ };
1734
+
1735
+ /**
1736
+ * Sync conditional reveal with the input state
1737
+ *
1738
+ * Synchronise the visibility of the conditional reveal, and its accessible
1739
+ * state, with the input's checked state.
1740
+ *
1741
+ * @param {HTMLInputElement} $input Checkbox input
1742
+ */
1743
+ Checkboxes.prototype.syncConditionalRevealWithInputState = function ($input) {
1744
+ var $target = this.$module.querySelector('#' + $input.getAttribute('aria-controls'));
1700
1745
 
1701
- var $content = this.$module.querySelector('#' + $input.getAttribute('aria-controls'));
1702
- if ($content) {
1703
- $content.classList.toggle('govuk-checkboxes__conditional--hidden', !inputIsChecked);
1746
+ if ($target && $target.classList.contains('govuk-checkboxes__conditional')) {
1747
+ var inputIsChecked = $input.checked;
1748
+
1749
+ $input.setAttribute('aria-expanded', inputIsChecked);
1750
+ $target.classList.toggle('govuk-checkboxes__conditional--hidden', !inputIsChecked);
1704
1751
  }
1705
1752
  };
1706
1753
 
1754
+ /**
1755
+ * Click event handler
1756
+ *
1757
+ * Handle a click within the $module – if the click occurred on a checkbox, sync
1758
+ * the state of any associated conditional reveal with the checkbox state.
1759
+ *
1760
+ * @param {MouseEvent} event Click event
1761
+ */
1707
1762
  Checkboxes.prototype.handleClick = function (event) {
1708
1763
  var $target = event.target;
1709
1764
 
@@ -1711,7 +1766,7 @@ Checkboxes.prototype.handleClick = function (event) {
1711
1766
  var isCheckbox = $target.getAttribute('type') === 'checkbox';
1712
1767
  var hasAriaControls = $target.getAttribute('aria-controls');
1713
1768
  if (isCheckbox && hasAriaControls) {
1714
- this.setAttributes($target);
1769
+ this.syncConditionalRevealWithInputState($target);
1715
1770
  }
1716
1771
  };
1717
1772
 
@@ -1959,67 +2014,115 @@ Header.prototype.handleClick = function (event) {
1959
2014
 
1960
2015
  function Radios ($module) {
1961
2016
  this.$module = $module;
2017
+ this.$inputs = $module.querySelectorAll('input[type="radio"]');
1962
2018
  }
1963
2019
 
2020
+ /**
2021
+ * Initialise Radios
2022
+ *
2023
+ * Radios can be associated with a 'conditionally revealed' content block – for
2024
+ * example, a radio for 'Phone' could reveal an additional form field for the
2025
+ * user to enter their phone number.
2026
+ *
2027
+ * These associations are made using a `data-aria-controls` attribute, which is
2028
+ * promoted to an aria-controls attribute during initialisation.
2029
+ *
2030
+ * We also need to restore the state of any conditional reveals on the page (for
2031
+ * example if the user has navigated back), and set up event handlers to keep
2032
+ * the reveal in sync with the radio state.
2033
+ */
1964
2034
  Radios.prototype.init = function () {
1965
2035
  var $module = this.$module;
1966
- var $inputs = $module.querySelectorAll('input[type="radio"]');
2036
+ var $inputs = this.$inputs;
1967
2037
 
1968
- /**
1969
- * Loop over all items with [data-controls]
1970
- * Check if they have a matching conditional reveal
1971
- * If they do, assign attributes.
1972
- **/
1973
2038
  nodeListForEach($inputs, function ($input) {
1974
- var controls = $input.getAttribute('data-aria-controls');
2039
+ var target = $input.getAttribute('data-aria-controls');
1975
2040
 
1976
- // Check if input controls anything
1977
- // Check if content exists, before setting attributes.
1978
- if (!controls || !$module.querySelector('#' + controls)) {
2041
+ // Skip radios without data-aria-controls attributes, or where the
2042
+ // target element does not exist.
2043
+ if (!target || !$module.querySelector('#' + target)) {
1979
2044
  return
1980
2045
  }
1981
2046
 
1982
- // If we have content that is controlled, set attributes.
1983
- $input.setAttribute('aria-controls', controls);
2047
+ // Promote the data-aria-controls attribute to a aria-controls attribute
2048
+ // so that the relationship is exposed in the AOM
2049
+ $input.setAttribute('aria-controls', target);
1984
2050
  $input.removeAttribute('data-aria-controls');
1985
- this.setAttributes($input);
1986
- }.bind(this));
2051
+ });
2052
+
2053
+ // When the page is restored after navigating 'back' in some browsers the
2054
+ // state of form controls is not restored until *after* the DOMContentLoaded
2055
+ // event is fired, so we need to sync after the pageshow event in browsers
2056
+ // that support it.
2057
+ if ('onpageshow' in window) {
2058
+ window.addEventListener('pageshow', this.syncAllConditionalReveals.bind(this));
2059
+ } else {
2060
+ window.addEventListener('DOMContentLoaded', this.syncAllConditionalReveals.bind(this));
2061
+ }
2062
+
2063
+ // Although we've set up handlers to sync state on the pageshow or
2064
+ // DOMContentLoaded event, init could be called after those events have fired,
2065
+ // for example if they are added to the page dynamically, so sync now too.
2066
+ this.syncAllConditionalReveals();
1987
2067
 
1988
2068
  // Handle events
1989
2069
  $module.addEventListener('click', this.handleClick.bind(this));
1990
2070
  };
1991
2071
 
1992
- Radios.prototype.setAttributes = function ($input) {
1993
- var $content = document.querySelector('#' + $input.getAttribute('aria-controls'));
2072
+ /**
2073
+ * Sync the conditional reveal states for all inputs in this $module.
2074
+ */
2075
+ Radios.prototype.syncAllConditionalReveals = function () {
2076
+ nodeListForEach(this.$inputs, this.syncConditionalRevealWithInputState.bind(this));
2077
+ };
1994
2078
 
1995
- if ($content && $content.classList.contains('govuk-radios__conditional')) {
2079
+ /**
2080
+ * Sync conditional reveal with the input state
2081
+ *
2082
+ * Synchronise the visibility of the conditional reveal, and its accessible
2083
+ * state, with the input's checked state.
2084
+ *
2085
+ * @param {HTMLInputElement} $input Radio input
2086
+ */
2087
+ Radios.prototype.syncConditionalRevealWithInputState = function ($input) {
2088
+ var $target = document.querySelector('#' + $input.getAttribute('aria-controls'));
2089
+
2090
+ if ($target && $target.classList.contains('govuk-radios__conditional')) {
1996
2091
  var inputIsChecked = $input.checked;
1997
2092
 
1998
2093
  $input.setAttribute('aria-expanded', inputIsChecked);
1999
-
2000
- $content.classList.toggle('govuk-radios__conditional--hidden', !inputIsChecked);
2094
+ $target.classList.toggle('govuk-radios__conditional--hidden', !inputIsChecked);
2001
2095
  }
2002
2096
  };
2003
2097
 
2098
+ /**
2099
+ * Click event handler
2100
+ *
2101
+ * Handle a click within the $module – if the click occurred on a radio, sync
2102
+ * the state of the conditional reveal for all radio buttons in the same form
2103
+ * with the same name (because checking one radio could have un-checked a radio
2104
+ * in another $module)
2105
+ *
2106
+ * @param {MouseEvent} event Click event
2107
+ */
2004
2108
  Radios.prototype.handleClick = function (event) {
2005
2109
  var $clickedInput = event.target;
2006
- // We only want to handle clicks for radio inputs
2110
+
2111
+ // Ignore clicks on things that aren't radio buttons
2007
2112
  if ($clickedInput.type !== 'radio') {
2008
2113
  return
2009
2114
  }
2010
- // Because checking one radio can uncheck a radio in another $module,
2011
- // we need to call set attributes on all radios in the same form, or document if they're not in a form.
2012
- //
2013
- // We also only want radios which have aria-controls, as they support conditional reveals.
2115
+
2116
+ // We only need to consider radios with conditional reveals, which will have
2117
+ // aria-controls attributes.
2014
2118
  var $allInputs = document.querySelectorAll('input[type="radio"][aria-controls]');
2119
+
2015
2120
  nodeListForEach($allInputs, function ($input) {
2016
- // Only inputs with the same form owner should change.
2017
2121
  var hasSameFormOwner = ($input.form === $clickedInput.form);
2018
-
2019
- // In radios, only radios with the same name will affect each other.
2020
2122
  var hasSameName = ($input.name === $clickedInput.name);
2123
+
2021
2124
  if (hasSameName && hasSameFormOwner) {
2022
- this.setAttributes($input);
2125
+ this.syncConditionalRevealWithInputState($input);
2023
2126
  }
2024
2127
  }.bind(this));
2025
2128
  };
@@ -11,10 +11,6 @@
11
11
  .govuk-textarea {
12
12
  margin-bottom: govuk-spacing(1);
13
13
  }
14
-
15
- .govuk-textarea--error {
16
- padding: govuk-spacing(1) - 2; // Stop a "jump" when width of border changes
17
- }
18
14
  }
19
15
 
20
16
  .govuk-character-count__message {
@@ -1062,13 +1062,22 @@ CharacterCount.prototype.init = function () {
1062
1062
  // Remove hard limit if set
1063
1063
  $module.removeAttribute('maxlength');
1064
1064
 
1065
- // Bind event changes to the textarea
1066
- var boundChangeEvents = this.bindChangeEvents.bind(this);
1067
- boundChangeEvents();
1065
+ // When the page is restored after navigating 'back' in some browsers the
1066
+ // state of the character count is not restored until *after* the DOMContentLoaded
1067
+ // event is fired, so we need to sync after the pageshow event in browsers
1068
+ // that support it.
1069
+ if ('onpageshow' in window) {
1070
+ window.addEventListener('pageshow', this.sync.bind(this));
1071
+ } else {
1072
+ window.addEventListener('DOMContentLoaded', this.sync.bind(this));
1073
+ }
1074
+
1075
+ this.sync();
1076
+ };
1068
1077
 
1069
- // Update count message
1070
- var boundUpdateCountMessage = this.updateCountMessage.bind(this);
1071
- boundUpdateCountMessage();
1078
+ CharacterCount.prototype.sync = function () {
1079
+ this.bindChangeEvents();
1080
+ this.updateCountMessage();
1072
1081
  };
1073
1082
 
1074
1083
  // Read data attributes
@@ -1116,8 +1125,7 @@ CharacterCount.prototype.checkIfValueChanged = function () {
1116
1125
  if (!this.$textarea.oldValue) this.$textarea.oldValue = '';
1117
1126
  if (this.$textarea.value !== this.$textarea.oldValue) {
1118
1127
  this.$textarea.oldValue = this.$textarea.value;
1119
- var boundUpdateCountMessage = this.updateCountMessage.bind(this);
1120
- boundUpdateCountMessage();
1128
+ this.updateCountMessage();
1121
1129
  }
1122
1130
  };
1123
1131
 
@@ -88,6 +88,12 @@
88
88
  "required": false,
89
89
  "description": "HTML attributes (for example data attributes) to add to the textarea."
90
90
  },
91
+ {
92
+ "name": "spellcheck",
93
+ "type": "boolean",
94
+ "required": false,
95
+ "description": "Optional field to enable or disable the spellcheck attribute on the character count."
96
+ },
91
97
  {
92
98
  "name": "countMessage",
93
99
  "type": "object",
@@ -10,6 +10,7 @@
10
10
  name: params.name,
11
11
  describedBy: params.id + '-info',
12
12
  rows: params.rows,
13
+ spellcheck: params.spellcheck,
13
14
  value: params.value,
14
15
  formGroup: params.formGroup,
15
16
  classes: 'govuk-js-character-count' + (' govuk-textarea--error' if params.errorMessage) + (' ' + params.classes if params.classes),
@@ -92,12 +92,13 @@
92
92
  // rotated 45 degrees
93
93
  .govuk-checkboxes__label::after {
94
94
  content: "";
95
+ box-sizing: border-box;
95
96
 
96
97
  position: absolute;
97
98
  top: 11px;
98
99
  left: 9px;
99
- width: 18px;
100
- height: 7px;
100
+ width: 23px;
101
+ height: 12px;
101
102
 
102
103
  -webkit-transform: rotate(-45deg);
103
104
 
@@ -105,7 +106,7 @@
105
106
 
106
107
  transform: rotate(-45deg);
107
108
  border: solid;
108
- border-width: 0 0 $govuk-border-width $govuk-border-width;
109
+ border-width: 0 0 5px 5px;
109
110
  // Fix bug in IE11 caused by transform rotate (-45deg).
110
111
  // See: alphagov/govuk_elements/issues/518
111
112
  border-top-color: transparent;
@@ -238,8 +239,8 @@
238
239
  .govuk-checkboxes__label::after {
239
240
  top: 15px;
240
241
  left: 6px;
241
- width: 9px;
242
- height: 3.5px;
242
+ width: 12px;
243
+ height: 6.5px;
243
244
  border-width: 0 0 3px 3px;
244
245
  }
245
246
 
@@ -1033,44 +1033,91 @@ function Checkboxes ($module) {
1033
1033
  this.$inputs = $module.querySelectorAll('input[type="checkbox"]');
1034
1034
  }
1035
1035
 
1036
+ /**
1037
+ * Initialise Checkboxes
1038
+ *
1039
+ * Checkboxes can be associated with a 'conditionally revealed' content block –
1040
+ * for example, a checkbox for 'Phone' could reveal an additional form field for
1041
+ * the user to enter their phone number.
1042
+ *
1043
+ * These associations are made using a `data-aria-controls` attribute, which is
1044
+ * promoted to an aria-controls attribute during initialisation.
1045
+ *
1046
+ * We also need to restore the state of any conditional reveals on the page (for
1047
+ * example if the user has navigated back), and set up event handlers to keep
1048
+ * the reveal in sync with the checkbox state.
1049
+ */
1036
1050
  Checkboxes.prototype.init = function () {
1037
1051
  var $module = this.$module;
1038
1052
  var $inputs = this.$inputs;
1039
1053
 
1040
- /**
1041
- * Loop over all items with [data-controls]
1042
- * Check if they have a matching conditional reveal
1043
- * If they do, assign attributes.
1044
- **/
1045
1054
  nodeListForEach($inputs, function ($input) {
1046
- var controls = $input.getAttribute('data-aria-controls');
1055
+ var target = $input.getAttribute('data-aria-controls');
1047
1056
 
1048
- // Check if input controls anything
1049
- // Check if content exists, before setting attributes.
1050
- if (!controls || !$module.querySelector('#' + controls)) {
1057
+ // Skip checkboxes without data-aria-controls attributes, or where the
1058
+ // target element does not exist.
1059
+ if (!target || !$module.querySelector('#' + target)) {
1051
1060
  return
1052
1061
  }
1053
1062
 
1054
- // If we have content that is controlled, set attributes.
1055
- $input.setAttribute('aria-controls', controls);
1063
+ // Promote the data-aria-controls attribute to a aria-controls attribute
1064
+ // so that the relationship is exposed in the AOM
1065
+ $input.setAttribute('aria-controls', target);
1056
1066
  $input.removeAttribute('data-aria-controls');
1057
- this.setAttributes($input);
1058
- }.bind(this));
1067
+ });
1068
+
1069
+ // When the page is restored after navigating 'back' in some browsers the
1070
+ // state of form controls is not restored until *after* the DOMContentLoaded
1071
+ // event is fired, so we need to sync after the pageshow event in browsers
1072
+ // that support it.
1073
+ if ('onpageshow' in window) {
1074
+ window.addEventListener('pageshow', this.syncAllConditionalReveals.bind(this));
1075
+ } else {
1076
+ window.addEventListener('DOMContentLoaded', this.syncAllConditionalReveals.bind(this));
1077
+ }
1078
+
1079
+ // Although we've set up handlers to sync state on the pageshow or
1080
+ // DOMContentLoaded event, init could be called after those events have fired,
1081
+ // for example if they are added to the page dynamically, so sync now too.
1082
+ this.syncAllConditionalReveals();
1059
1083
 
1060
- // Handle events
1061
1084
  $module.addEventListener('click', this.handleClick.bind(this));
1062
1085
  };
1063
1086
 
1064
- Checkboxes.prototype.setAttributes = function ($input) {
1065
- var inputIsChecked = $input.checked;
1066
- $input.setAttribute('aria-expanded', inputIsChecked);
1087
+ /**
1088
+ * Sync the conditional reveal states for all inputs in this $module.
1089
+ */
1090
+ Checkboxes.prototype.syncAllConditionalReveals = function () {
1091
+ nodeListForEach(this.$inputs, this.syncConditionalRevealWithInputState.bind(this));
1092
+ };
1093
+
1094
+ /**
1095
+ * Sync conditional reveal with the input state
1096
+ *
1097
+ * Synchronise the visibility of the conditional reveal, and its accessible
1098
+ * state, with the input's checked state.
1099
+ *
1100
+ * @param {HTMLInputElement} $input Checkbox input
1101
+ */
1102
+ Checkboxes.prototype.syncConditionalRevealWithInputState = function ($input) {
1103
+ var $target = this.$module.querySelector('#' + $input.getAttribute('aria-controls'));
1067
1104
 
1068
- var $content = this.$module.querySelector('#' + $input.getAttribute('aria-controls'));
1069
- if ($content) {
1070
- $content.classList.toggle('govuk-checkboxes__conditional--hidden', !inputIsChecked);
1105
+ if ($target && $target.classList.contains('govuk-checkboxes__conditional')) {
1106
+ var inputIsChecked = $input.checked;
1107
+
1108
+ $input.setAttribute('aria-expanded', inputIsChecked);
1109
+ $target.classList.toggle('govuk-checkboxes__conditional--hidden', !inputIsChecked);
1071
1110
  }
1072
1111
  };
1073
1112
 
1113
+ /**
1114
+ * Click event handler
1115
+ *
1116
+ * Handle a click within the $module – if the click occurred on a checkbox, sync
1117
+ * the state of any associated conditional reveal with the checkbox state.
1118
+ *
1119
+ * @param {MouseEvent} event Click event
1120
+ */
1074
1121
  Checkboxes.prototype.handleClick = function (event) {
1075
1122
  var $target = event.target;
1076
1123
 
@@ -1078,7 +1125,7 @@ Checkboxes.prototype.handleClick = function (event) {
1078
1125
  var isCheckbox = $target.getAttribute('type') === 'checkbox';
1079
1126
  var hasAriaControls = $target.getAttribute('aria-controls');
1080
1127
  if (isCheckbox && hasAriaControls) {
1081
- this.setAttributes($target);
1128
+ this.syncConditionalRevealWithInputState($target);
1082
1129
  }
1083
1130
  };
1084
1131