govuk_publishing_components 23.3.0 → 23.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/govuk_publishing_components/components/copy-to-clipboard.js +16 -14
  3. data/app/assets/javascripts/govuk_publishing_components/components/details.js +38 -34
  4. data/app/assets/javascripts/govuk_publishing_components/components/print-link.js +8 -7
  5. data/app/assets/javascripts/govuk_publishing_components/lib/govspeak/magna-charta.js +10 -9
  6. data/app/assets/javascripts/govuk_publishing_components/lib/initial-focus.js +13 -0
  7. data/app/assets/stylesheets/govuk_publishing_components/_all_components.scss +1 -0
  8. data/app/assets/stylesheets/govuk_publishing_components/components/_contextual-sidebar.scss +2 -0
  9. data/app/assets/stylesheets/govuk_publishing_components/components/_image-card.scss +1 -0
  10. data/app/assets/stylesheets/govuk_publishing_components/components/_input.scss +0 -46
  11. data/app/assets/stylesheets/govuk_publishing_components/components/_transition-countdown.scss +125 -0
  12. data/app/views/govuk_publishing_components/component_guide/show.html.erb +1 -2
  13. data/app/views/govuk_publishing_components/components/_attachment.html.erb +5 -4
  14. data/app/views/govuk_publishing_components/components/_contextual_sidebar.html.erb +14 -1
  15. data/app/views/govuk_publishing_components/components/_input.html.erb +6 -6
  16. data/app/views/govuk_publishing_components/components/_transition_countdown.html.erb +34 -0
  17. data/app/views/govuk_publishing_components/components/contextual_sidebar/_brexit_cta.html.erb +5 -3
  18. data/app/views/govuk_publishing_components/components/docs/attachment.yml +10 -0
  19. data/app/views/govuk_publishing_components/components/docs/contextual_sidebar.yml +0 -1
  20. data/app/views/govuk_publishing_components/components/docs/govspeak.yml +55 -0
  21. data/app/views/govuk_publishing_components/components/docs/transition_countdown.yml +17 -0
  22. data/config/locales/cy.yml +9 -1
  23. data/config/locales/en.yml +7 -0
  24. data/lib/govuk_publishing_components.rb +1 -0
  25. data/lib/govuk_publishing_components/app_helpers/countdown_helper.rb +33 -0
  26. data/lib/govuk_publishing_components/version.rb +1 -1
  27. data/node_modules/govuk-frontend/govuk/all.js +31 -37
  28. data/node_modules/govuk-frontend/govuk/components/accordion/README.md +1 -1
  29. data/node_modules/govuk-frontend/govuk/components/accordion/_index.scss +0 -1
  30. data/node_modules/govuk-frontend/govuk/components/accordion/fixtures.json +235 -0
  31. data/node_modules/govuk-frontend/govuk/components/back-link/_index.scss +0 -2
  32. data/node_modules/govuk-frontend/govuk/components/back-link/fixtures.json +56 -0
  33. data/node_modules/govuk-frontend/govuk/components/breadcrumbs/_index.scss +0 -1
  34. data/node_modules/govuk-frontend/govuk/components/breadcrumbs/fixtures.json +172 -0
  35. data/node_modules/govuk-frontend/govuk/components/button/_index.scss +3 -3
  36. data/node_modules/govuk-frontend/govuk/components/button/fixtures.json +275 -0
  37. data/node_modules/govuk-frontend/govuk/components/character-count/fixtures.json +170 -0
  38. data/node_modules/govuk-frontend/govuk/components/checkboxes/_index.scss +13 -13
  39. data/node_modules/govuk-frontend/govuk/components/checkboxes/fixtures.json +1015 -0
  40. data/node_modules/govuk-frontend/govuk/components/date-input/fixtures.json +499 -0
  41. data/node_modules/govuk-frontend/govuk/components/details/_index.scss +0 -1
  42. data/node_modules/govuk-frontend/govuk/components/details/fixtures.json +83 -0
  43. data/node_modules/govuk-frontend/govuk/components/error-message/fixtures.json +66 -0
  44. data/node_modules/govuk-frontend/govuk/components/error-summary/_index.scss +0 -2
  45. data/node_modules/govuk-frontend/govuk/components/error-summary/fixtures.json +181 -0
  46. data/node_modules/govuk-frontend/govuk/components/fieldset/_index.scss +1 -1
  47. data/node_modules/govuk-frontend/govuk/components/fieldset/fixtures.json +93 -0
  48. data/node_modules/govuk-frontend/govuk/components/fieldset/macro-options.json +6 -0
  49. data/node_modules/govuk-frontend/govuk/components/fieldset/template.njk +5 -1
  50. data/node_modules/govuk-frontend/govuk/components/file-upload/fixtures.json +151 -0
  51. data/node_modules/govuk-frontend/govuk/components/footer/_index.scss +0 -1
  52. data/node_modules/govuk-frontend/govuk/components/footer/fixtures.json +482 -0
  53. data/node_modules/govuk-frontend/govuk/components/header/_index.scss +2 -5
  54. data/node_modules/govuk-frontend/govuk/components/header/fixtures.json +360 -0
  55. data/node_modules/govuk-frontend/govuk/components/header/header.js +665 -316
  56. data/node_modules/govuk-frontend/govuk/components/header/macro-options.json +13 -1
  57. data/node_modules/govuk-frontend/govuk/components/header/template.njk +9 -5
  58. data/node_modules/govuk-frontend/govuk/components/hint/_index.scss +0 -2
  59. data/node_modules/govuk-frontend/govuk/components/hint/fixtures.json +50 -0
  60. data/node_modules/govuk-frontend/govuk/components/hint/macro-options.json +1 -1
  61. data/node_modules/govuk-frontend/govuk/components/input/_index.scss +91 -0
  62. data/node_modules/govuk-frontend/govuk/components/input/fixtures.json +538 -0
  63. data/node_modules/govuk-frontend/govuk/components/input/macro-options.json +64 -0
  64. data/node_modules/govuk-frontend/govuk/components/input/template.njk +17 -0
  65. data/node_modules/govuk-frontend/govuk/components/inset-text/fixtures.json +49 -0
  66. data/node_modules/govuk-frontend/govuk/components/label/fixtures.json +75 -0
  67. data/node_modules/govuk-frontend/govuk/components/panel/_index.scss +6 -2
  68. data/node_modules/govuk-frontend/govuk/components/panel/fixtures.json +74 -0
  69. data/node_modules/govuk-frontend/govuk/components/phase-banner/fixtures.json +65 -0
  70. data/node_modules/govuk-frontend/govuk/components/radios/_index.scss +13 -13
  71. data/node_modules/govuk-frontend/govuk/components/radios/fixtures.json +1066 -0
  72. data/node_modules/govuk-frontend/govuk/components/radios/macro-options.json +2 -2
  73. data/node_modules/govuk-frontend/govuk/components/select/_index.scss +0 -1
  74. data/node_modules/govuk-frontend/govuk/components/select/fixtures.json +248 -0
  75. data/node_modules/govuk-frontend/govuk/components/skip-link/fixtures.json +72 -0
  76. data/node_modules/govuk-frontend/govuk/components/summary-list/README.md +1 -1
  77. data/node_modules/govuk-frontend/govuk/components/summary-list/_index.scss +2 -10
  78. data/node_modules/govuk-frontend/govuk/components/summary-list/fixtures.json +991 -0
  79. data/node_modules/govuk-frontend/govuk/components/table/fixtures.json +468 -0
  80. data/node_modules/govuk-frontend/govuk/components/tabs/_index.scss +3 -6
  81. data/node_modules/govuk-frontend/govuk/components/tabs/fixtures.json +229 -0
  82. data/node_modules/govuk-frontend/govuk/components/tag/_index.scss +0 -1
  83. data/node_modules/govuk-frontend/govuk/components/tag/fixtures.json +117 -0
  84. data/node_modules/govuk-frontend/govuk/components/textarea/_index.scss +0 -1
  85. data/node_modules/govuk-frontend/govuk/components/textarea/fixtures.json +199 -0
  86. data/node_modules/govuk-frontend/govuk/components/warning-text/_index.scss +0 -1
  87. data/node_modules/govuk-frontend/govuk/components/warning-text/fixtures.json +68 -0
  88. data/node_modules/govuk-frontend/govuk/helpers/_device-pixels.scss +3 -3
  89. data/node_modules/govuk-frontend/govuk/helpers/_font-faces.scss +9 -11
  90. data/node_modules/govuk-frontend/govuk/helpers/_links.scss +1 -3
  91. data/node_modules/govuk-frontend/govuk/helpers/_media-queries.scss +1 -5
  92. data/node_modules/govuk-frontend/govuk/helpers/_spacing.scss +2 -1
  93. data/node_modules/govuk-frontend/govuk/helpers/_typography.scss +7 -6
  94. data/node_modules/govuk-frontend/govuk/objects/_form-group.scss +0 -1
  95. data/node_modules/govuk-frontend/govuk/objects/_grid.scss +2 -3
  96. data/node_modules/govuk-frontend/govuk/objects/_main-wrapper.scss +0 -1
  97. data/node_modules/govuk-frontend/govuk/overrides/_display.scss +1 -1
  98. data/node_modules/govuk-frontend/govuk/overrides/_width.scss +1 -0
  99. data/node_modules/govuk-frontend/govuk/settings/_colours-applied.scss +0 -3
  100. data/node_modules/govuk-frontend/govuk/settings/_colours-organisations.scss +3 -0
  101. data/node_modules/govuk-frontend/govuk/settings/_colours-palette.scss +9 -2
  102. data/node_modules/govuk-frontend/govuk/settings/_compatibility.scss +0 -1
  103. data/node_modules/govuk-frontend/govuk/settings/_measurements.scss +0 -4
  104. data/node_modules/govuk-frontend/govuk/settings/_typography-font-families.scss +2 -2
  105. data/node_modules/govuk-frontend/govuk/settings/_typography-font.scss +11 -5
  106. data/node_modules/govuk-frontend/govuk/settings/_typography-responsive.scss +6 -2
  107. data/node_modules/govuk-frontend/govuk/tools/_font-url.scss +0 -3
  108. data/node_modules/govuk-frontend/govuk/tools/_image-url.scss +0 -3
  109. data/node_modules/govuk-frontend/govuk/utilities/_visually-hidden.scss +0 -1
  110. data/node_modules/govuk-frontend/govuk/vendor/_sass-mq.scss +0 -4
  111. data/node_modules/govuk-frontend/package.json +1 -1
  112. metadata +36 -3
  113. data/app/assets/javascripts/govuk_publishing_components/components/initial-focus.js +0 -12
@@ -1,8 +1,21 @@
1
1
  <% navigation = GovukPublishingComponents::Presenters::ContextualNavigation.new(content_item, request) %>
2
2
 
3
3
  <div class="gem-c-contextual-sidebar">
4
- <% if navigation.show_brexit_cta? && navigation.step_by_step_count.eql?(0) %>
4
+ <% if navigation.show_brexit_cta? && navigation.step_by_step_count.zero? %>
5
5
  <%= render 'govuk_publishing_components/components/contextual_sidebar/brexit_cta' %>
6
+ <% elsif navigation.step_by_step_count.zero? %>
7
+ <%= render 'govuk_publishing_components/components/transition_countdown', {
8
+ title: t("components.related_navigation.transition.title"),
9
+ url: t("components.related_navigation.transition.link_path"),
10
+ text: t("components.related_navigation.transition.link_text"),
11
+ data_attributes: {
12
+ "track-category": "relatedLinkClicked",
13
+ "track-action": "1.0 Transition",
14
+ "track-label": t("components.related_navigation.transition.link_path"),
15
+ "track-options": "{'dimension29':'#{t("components.related_navigation.transition.link_text")}'}"
16
+ },
17
+ lang: I18n.locale,
18
+ } %>
6
19
  <% end %>
7
20
 
8
21
  <% if navigation.content_tagged_to_a_reasonable_number_of_step_by_steps? %>
@@ -107,17 +107,17 @@
107
107
  %>
108
108
 
109
109
  <% if prefix && suffix %>
110
- <%= tag.div class: "gem-c-input__wrapper" do %>
110
+ <%= tag.div class: "govuk-input__wrapper" do %>
111
111
  <% # The line below relies on in-line styling for legacy browsers and it's whitespace-sensitive %>
112
- <%= tag.span prefix, class: "gem-c-input__prefix", aria: { hidden: true } %><%= input_tag %><%= tag.span suffix, class: "gem-c-input__suffix", aria: { hidden: true } %>
112
+ <%= tag.span prefix, class: "govuk-input__prefix", aria: { hidden: true } %><%= input_tag %><%= tag.span suffix, class: "govuk-input__suffix", aria: { hidden: true } %>
113
113
  <% end %>
114
114
  <% elsif prefix %>
115
- <%= tag.div class: "gem-c-input__wrapper" do %>
116
- <%= tag.span prefix, class: "gem-c-input__prefix", aria: { hidden: true } %><%= input_tag %>
115
+ <%= tag.div class: "govuk-input__wrapper" do %>
116
+ <%= tag.span prefix, class: "govuk-input__prefix", aria: { hidden: true } %><%= input_tag %>
117
117
  <% end %>
118
118
  <% elsif suffix %>
119
- <%= tag.div class: "gem-c-input__wrapper" do %>
120
- <%= input_tag %><%= tag.span suffix, class: "gem-c-input__suffix", aria: { hidden: true } %>
119
+ <%= tag.div class: "govuk-input__wrapper" do %>
120
+ <%= input_tag %><%= tag.span suffix, class: "govuk-input__suffix", aria: { hidden: true } %>
121
121
  <% end %>
122
122
  <% else %>
123
123
  <%= input_tag %>
@@ -0,0 +1,34 @@
1
+ <%
2
+ countdown_clock = GovukPublishingComponents::AppHelpers::CountdownHelper.new
3
+ shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)
4
+
5
+ heading_level ||= 2
6
+ title ||= nil
7
+ text ||= nil
8
+ url ||= nil
9
+ data_attributes ||= {}
10
+ lang ||= 'en'
11
+ css_classes = %w(gem-c-transition-countdown)
12
+ css_classes << 'gem-c-transition-countdown--cta' if url
13
+ css_classes << 'govuk-link' if url
14
+ %>
15
+
16
+ <% countdown = capture do %>
17
+ <%= content_tag(shared_helper.get_heading_level, title, class: "gem-c-transition-countdown__title") if title %>
18
+ <% if countdown_clock.show? %>
19
+ <%= tag.p class: "gem-c-transition-countdown__countdown" do %>
20
+ <%= tag.span countdown_clock.days_left.first, class: "gem-c-transition-countdown__countdown-number" %><%= tag.span countdown_clock.days_left.last, class: "gem-c-transition-countdown__countdown-number" %> <%= tag.span countdown_clock.days_text, class: "gem-c-transition-countdown__countdown-text" %>
21
+ <% end %>
22
+ <% end %>
23
+ <%= tag.p text, class: "gem-c-transition-countdown__text" if text %>
24
+ <% end %>
25
+
26
+ <% if url %>
27
+ <%= link_to url, class: css_classes, data: data_attributes, lang: lang do %>
28
+ <%= countdown %>
29
+ <% end %>
30
+ <% else %>
31
+ <%= tag.div class: css_classes, lang: lang do %>
32
+ <%= countdown %>
33
+ <% end %>
34
+ <% end %>
@@ -1,4 +1,6 @@
1
- <div class="gem-c-contextual-sidebar__brexit-cta govuk-!-margin-bottom-6" data-module="track-click">
2
- <h2 class="gem-c-contextual-sidebar__brexit-heading">Transition period</h2>
3
- <a href="/transition" class="govuk-link" data-track-category="relatedLinkClicked" data-track-action="1.0 Transition" data-track-label="/transition" data-track-options='{"dimension29":"Find out what it means for you"}'>Find out what it means for you</a>
1
+ <% link_text = t("components.related_navigation.transition.link_text") %>
2
+ <% link_path = t("components.related_navigation.transition.link_path") %>
3
+ <div class="gem-c-contextual-sidebar__brexit-cta govuk-!-margin-bottom-6" data-module="track-click" lang="en">
4
+ <h2 class="gem-c-contextual-sidebar__brexit-heading"><%= t("components.related_navigation.transition.title") %></h2>
5
+ <a href="<%= link_path %>" class="govuk-link" data-track-category="relatedLinkClicked" data-track-action="1.0 Transition" data-track-label="<%= link_path %>" data-track-options='{"dimension29":"<%= link_text %>"}'><%= link_text %></a>
4
6
  </div>
@@ -158,3 +158,13 @@ examples:
158
158
  unique_reference: "2942"
159
159
  unnumbered_hoc_paper: true
160
160
  hide_order_copy_link: true
161
+ with_custom_heading_level:
162
+ description: Default is `h2`.
163
+ data:
164
+ heading_level: 3
165
+ attachment:
166
+ title: "Department for Transport information asset register"
167
+ url: https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/747661/department-for-transport-information-asset-register.csv
168
+ filename: department-for-transport-information-asset-register.csv
169
+ content_type: text/csv
170
+ file_size: 20000
@@ -144,4 +144,3 @@ examples:
144
144
  - text: Find out what you’ll get
145
145
  href: "/settled-status-eu-citizens-families/what-settled-and-presettled-status-means"
146
146
  optional: false
147
-
@@ -236,6 +236,61 @@ examples:
236
236
  </tr>
237
237
  </tbody>
238
238
  </table>
239
+ stacked_chart:
240
+ data:
241
+ block: |
242
+ <table class="js-barchart-table mc-stacked mc-auto-outdent">
243
+ <thead>
244
+ <tr>
245
+ <th scope="col">Colours</th>
246
+ <th scope="col">Fruits</th>
247
+ <th scope="col">Vegetables</th>
248
+ <th scope="col">Beans</th>
249
+ <th scope="col">Nuts</th>
250
+ <th scope="col">Total</th>
251
+ </tr>
252
+ </thead>
253
+ <tbody>
254
+ <tr>
255
+ <td>Red</td>
256
+ <td>23</td>
257
+ <td>9</td>
258
+ <td>2</td>
259
+ <td>1</td>
260
+ <td>35</td>
261
+ </tr>
262
+ <tr>
263
+ <td>Green</td>
264
+ <td>5</td>
265
+ <td>33</td>
266
+ <td>8</td>
267
+ <td>0</td>
268
+ <td>46</td>
269
+ </tr>
270
+ <tr>
271
+ <td>Yellow</td>
272
+ <td>2</td>
273
+ <td>10</td>
274
+ <td>0</td>
275
+ <td>15</td>
276
+ <td>27</td>
277
+ </tr>
278
+ </tbody>
279
+ </table>
280
+ chart_with_multiple_headings:
281
+ data:
282
+ block: |
283
+ <table id="multiple-table-chart" class="js-barchart-table mc-multiple">
284
+ <caption>Multiple Table</caption>
285
+ <thead>
286
+ <tr><th>Some Data</th><th>YES</th><th>NO</th><th>MAYBE</th></tr>
287
+ </thead>
288
+ <tbody>
289
+ <tr><th>Testing One</th><td>5</td><td>6</td><td>11</td></tr>
290
+ <tr><th>Testing Two</th><td>6</td><td>2</td><td>8</td></tr>
291
+ <tr><th>Testing Three</th><td>3</td><td>9</td><td>12</td></tr>
292
+ </tbody>
293
+ </table>
239
294
  address:
240
295
  data:
241
296
  block: |
@@ -0,0 +1,17 @@
1
+ name: Transition countdown
2
+ description: A countdown to 01 January 2021 used in the Brexit transition campaign
3
+ body: When a URL is set it acts as a link to actions users need to take to prepare for brexit during the transition period
4
+ shared_accessibility_criteria:
5
+ - link
6
+ examples:
7
+ default:
8
+ data:
9
+ call_to_action:
10
+ data:
11
+ title: Brexit transition
12
+ text: Check you’re ready for 2021
13
+ url: "https://www.gov.uk/transition"
14
+ data_attributes:
15
+ "track-category": "Transition"
16
+ "track-action": "Brexit transition"
17
+ "track-label": "Check you’re ready for 2021"
@@ -6,5 +6,13 @@ cy:
6
6
  or: 'neu'
7
7
  back_link:
8
8
  back: "Yn ôl"
9
- contents_list:
9
+ contents_list:
10
10
  contents: Cynnwys
11
+ related_navigation:
12
+ transition:
13
+ title: "Pontio Brexit"
14
+ link_path: "/transition.cy"
15
+ link_text: "Gwiriwch eich bod chi'n barod ar gyfer 2021"
16
+ transition_countdown:
17
+ day_to_go: "diwrnod i fynd"
18
+ days_to_go: "diwrnod i fynd"
@@ -71,6 +71,10 @@ en:
71
71
  topics: "Explore the topic"
72
72
  topical_events: "Topical event"
73
73
  world_locations: "World locations"
74
+ transition:
75
+ title: "Brexit transition"
76
+ link_path: "/transition"
77
+ link_text: "Check you’re ready for 2021"
74
78
  related_footer_navigation:
75
79
  collections: "Collections"
76
80
  policies: "Policies"
@@ -94,3 +98,6 @@ en:
94
98
  summary_list:
95
99
  edit: "Change"
96
100
  delete: "Delete"
101
+ transition_countdown:
102
+ day_to_go: "day to go"
103
+ days_to_go: "days to go"
@@ -34,6 +34,7 @@ require "govuk_publishing_components/presenters/taxonomy_list_helper"
34
34
  require "govuk_publishing_components/app_helpers/taxon_breadcrumbs"
35
35
  require "govuk_publishing_components/app_helpers/table_helper"
36
36
  require "govuk_publishing_components/app_helpers/brand_helper"
37
+ require "govuk_publishing_components/app_helpers/countdown_helper"
37
38
  require "govuk_publishing_components/app_helpers/environment"
38
39
 
39
40
  # Add view and i18n paths for usage outside of a Rails app
@@ -0,0 +1,33 @@
1
+ module GovukPublishingComponents
2
+ module AppHelpers
3
+ class CountdownHelper
4
+ END_OF_TRANSITION_PERIOD = Date.new(2021, 1, 1)
5
+
6
+ def days_left
7
+ sprintf "%02d", days_left_integer
8
+ end
9
+
10
+ def show?
11
+ days_left_integer.positive?
12
+ end
13
+
14
+ def days_text
15
+ if days_left_integer == 1
16
+ I18n.t!("components.transition_countdown.day_to_go")
17
+ else
18
+ I18n.t!("components.transition_countdown.days_to_go")
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def days_left_integer
25
+ (END_OF_TRANSITION_PERIOD - today_in_london).to_i
26
+ end
27
+
28
+ def today_in_london
29
+ Time.find_zone("Europe/London").today
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "23.3.0".freeze
2
+ VERSION = "23.7.0".freeze
3
3
  end
@@ -1961,55 +1961,49 @@ ErrorSummary.prototype.getAssociatedLegendOrLabel = function ($input) {
1961
1961
 
1962
1962
  function Header ($module) {
1963
1963
  this.$module = $module;
1964
+ this.$menuButton = $module && $module.querySelector('.govuk-js-header-toggle');
1965
+ this.$menu = this.$menuButton && $module.querySelector(
1966
+ '#' + this.$menuButton.getAttribute('aria-controls')
1967
+ );
1964
1968
  }
1965
1969
 
1970
+ /**
1971
+ * Initialise header
1972
+ *
1973
+ * Check for the presence of the header, menu and menu button – if any are
1974
+ * missing then there's nothing to do so return early.
1975
+ */
1966
1976
  Header.prototype.init = function () {
1967
- // Check for module
1968
- var $module = this.$module;
1969
- if (!$module) {
1977
+ if (!this.$module || !this.$menuButton || !this.$menu) {
1970
1978
  return
1971
1979
  }
1972
1980
 
1973
- // Check for button
1974
- var $toggleButton = $module.querySelector('.govuk-js-header-toggle');
1975
- if (!$toggleButton) {
1976
- return
1977
- }
1978
-
1979
- // Handle $toggleButton click events
1980
- $toggleButton.addEventListener('click', this.handleClick.bind(this));
1981
+ this.syncState(this.$menu.classList.contains('govuk-header__navigation--open'));
1982
+ this.$menuButton.addEventListener('click', this.handleMenuButtonClick.bind(this));
1981
1983
  };
1982
1984
 
1983
1985
  /**
1984
- * Toggle class
1985
- * @param {object} node element
1986
- * @param {string} className to toggle
1987
- */
1988
- Header.prototype.toggleClass = function (node, className) {
1989
- if (node.className.indexOf(className) > 0) {
1990
- node.className = node.className.replace(' ' + className, '');
1991
- } else {
1992
- node.className += ' ' + className;
1993
- }
1986
+ * Sync menu state
1987
+ *
1988
+ * Sync the menu button class and the accessible state of the menu and the menu
1989
+ * button with the visible state of the menu
1990
+ *
1991
+ * @param {boolean} isVisible Whether the menu is currently visible
1992
+ */
1993
+ Header.prototype.syncState = function (isVisible) {
1994
+ this.$menuButton.classList.toggle('govuk-header__menu-button--open', isVisible);
1995
+ this.$menuButton.setAttribute('aria-expanded', isVisible);
1994
1996
  };
1995
1997
 
1996
1998
  /**
1997
- * An event handler for click event on $toggleButton
1998
- * @param {object} event event
1999
- */
2000
- Header.prototype.handleClick = function (event) {
2001
- var $module = this.$module;
2002
- var $toggleButton = event.target || event.srcElement;
2003
- var $target = $module.querySelector('#' + $toggleButton.getAttribute('aria-controls'));
2004
-
2005
- // If a button with aria-controls, handle click
2006
- if ($toggleButton && $target) {
2007
- this.toggleClass($target, 'govuk-header__navigation--open');
2008
- this.toggleClass($toggleButton, 'govuk-header__menu-button--open');
2009
-
2010
- $toggleButton.setAttribute('aria-expanded', $toggleButton.getAttribute('aria-expanded') !== 'true');
2011
- $target.setAttribute('aria-hidden', $target.getAttribute('aria-hidden') === 'false');
2012
- }
1999
+ * Handle menu button click
2000
+ *
2001
+ * When the menu button is clicked, change the visibility of the menu and then
2002
+ * sync the accessibility state and menu button state
2003
+ */
2004
+ Header.prototype.handleMenuButtonClick = function () {
2005
+ var isVisible = this.$menu.classList.toggle('govuk-header__navigation--open');
2006
+ this.syncState(isVisible);
2013
2007
  };
2014
2008
 
2015
2009
  function Radios ($module) {
@@ -6,7 +6,7 @@ See the [main README quick start guide](https://github.com/alphagov/govuk-fronte
6
6
 
7
7
  ## Guidance and Examples
8
8
 
9
- Find out when to use the details component in your service in the [GOV.UK Design System](https://design-system.service.gov.uk/components/accordion).
9
+ Find out when to use the accordion component in your service in the [GOV.UK Design System](https://design-system.service.gov.uk/components/accordion).
10
10
 
11
11
  ## Component options
12
12
 
@@ -47,7 +47,6 @@
47
47
 
48
48
  // JavaScript enabled
49
49
  .js-enabled {
50
-
51
50
  .govuk-accordion {
52
51
  // Border at the bottom of the whole accordion
53
52
  border-bottom: 1px solid $govuk-border-colour;
@@ -0,0 +1,235 @@
1
+ {
2
+ "component": "accordion",
3
+ "fixtures": [
4
+ {
5
+ "name": "default",
6
+ "options": {
7
+ "id": "default-example",
8
+ "items": [
9
+ {
10
+ "heading": {
11
+ "text": "Section A"
12
+ },
13
+ "content": {
14
+ "html": "<ul class=\"govuk-list govuk-list--bullet\">\n <li>Example item 1</li>\n</ul>\n"
15
+ }
16
+ },
17
+ {
18
+ "heading": {
19
+ "text": "Section B"
20
+ },
21
+ "content": {
22
+ "html": "<ul class=\"govuk-list govuk-list--bullet\">\n <li>Example item 2</li>\n</ul>\n"
23
+ }
24
+ }
25
+ ]
26
+ },
27
+ "html": "<div class=\"govuk-accordion\" data-module=\"govuk-accordion\" id=\"default-example\">\n \n \n <div class=\"govuk-accordion__section \">\n <div class=\"govuk-accordion__section-header\">\n <h2 class=\"govuk-accordion__section-heading\">\n <span class=\"govuk-accordion__section-button\" id=\"default-example-heading-1\">\n Section A\n </span>\n </h2>\n \n </div>\n <div id=\"default-example-content-1\" class=\"govuk-accordion__section-content\" aria-labelledby=\"default-example-heading-1\">\n <ul class=\"govuk-list govuk-list--bullet\">\n <li>Example item 1</li>\n</ul>\n\n </div>\n </div>\n \n \n \n <div class=\"govuk-accordion__section \">\n <div class=\"govuk-accordion__section-header\">\n <h2 class=\"govuk-accordion__section-heading\">\n <span class=\"govuk-accordion__section-button\" id=\"default-example-heading-2\">\n Section B\n </span>\n </h2>\n \n </div>\n <div id=\"default-example-content-2\" class=\"govuk-accordion__section-content\" aria-labelledby=\"default-example-heading-2\">\n <ul class=\"govuk-list govuk-list--bullet\">\n <li>Example item 2</li>\n</ul>\n\n </div>\n </div>\n \n \n</div>"
28
+ },
29
+ {
30
+ "name": "with additional descriptions",
31
+ "options": {
32
+ "id": "with-descriptions",
33
+ "items": [
34
+ {
35
+ "heading": {
36
+ "text": "Test"
37
+ },
38
+ "summary": {
39
+ "text": "Additional description"
40
+ },
41
+ "content": {
42
+ "html": "<ul class=\"govuk-list govuk-list--bullet\">\n <li>Example item 1</li>\n</ul>\n"
43
+ }
44
+ },
45
+ {
46
+ "heading": {
47
+ "text": "Test 2"
48
+ },
49
+ "summary": {
50
+ "html": "<span class=\"govuk-!-font-weight-regular\">Additional description</span>"
51
+ },
52
+ "content": {
53
+ "html": "<ul class=\"govuk-list govuk-list--bullet\">\n <li>Example item 2</li>\n</ul>\n"
54
+ }
55
+ }
56
+ ]
57
+ },
58
+ "html": "<div class=\"govuk-accordion\" data-module=\"govuk-accordion\" id=\"with-descriptions\">\n \n \n <div class=\"govuk-accordion__section \">\n <div class=\"govuk-accordion__section-header\">\n <h2 class=\"govuk-accordion__section-heading\">\n <span class=\"govuk-accordion__section-button\" id=\"with-descriptions-heading-1\">\n Test\n </span>\n </h2>\n \n <div class=\"govuk-accordion__section-summary govuk-body\" id=\"with-descriptions-summary-1\">\n Additional description\n </div>\n \n </div>\n <div id=\"with-descriptions-content-1\" class=\"govuk-accordion__section-content\" aria-labelledby=\"with-descriptions-heading-1\">\n <ul class=\"govuk-list govuk-list--bullet\">\n <li>Example item 1</li>\n</ul>\n\n </div>\n </div>\n \n \n \n <div class=\"govuk-accordion__section \">\n <div class=\"govuk-accordion__section-header\">\n <h2 class=\"govuk-accordion__section-heading\">\n <span class=\"govuk-accordion__section-button\" id=\"with-descriptions-heading-2\">\n Test 2\n </span>\n </h2>\n \n <div class=\"govuk-accordion__section-summary govuk-body\" id=\"with-descriptions-summary-2\">\n <span class=\"govuk-!-font-weight-regular\">Additional description</span>\n </div>\n \n </div>\n <div id=\"with-descriptions-content-2\" class=\"govuk-accordion__section-content\" aria-labelledby=\"with-descriptions-heading-2\">\n <ul class=\"govuk-list govuk-list--bullet\">\n <li>Example item 2</li>\n</ul>\n\n </div>\n </div>\n \n \n</div>"
59
+ },
60
+ {
61
+ "name": "with one section open",
62
+ "options": {
63
+ "id": "one-section-open-example",
64
+ "items": [
65
+ {
66
+ "heading": {
67
+ "text": "Section A"
68
+ },
69
+ "expanded": true,
70
+ "content": {
71
+ "html": "<ul class=\"govuk-list govuk-list--bullet\">\n <li>Example item 1</li>\n</ul>\n"
72
+ }
73
+ },
74
+ {
75
+ "heading": {
76
+ "text": "Section B"
77
+ },
78
+ "content": {
79
+ "html": "<ul class=\"govuk-list govuk-list--bullet\">\n <li>Example item 2</li>\n</ul>\n"
80
+ }
81
+ }
82
+ ]
83
+ },
84
+ "html": "<div class=\"govuk-accordion\" data-module=\"govuk-accordion\" id=\"one-section-open-example\">\n \n \n <div class=\"govuk-accordion__section govuk-accordion__section--expanded\">\n <div class=\"govuk-accordion__section-header\">\n <h2 class=\"govuk-accordion__section-heading\">\n <span class=\"govuk-accordion__section-button\" id=\"one-section-open-example-heading-1\">\n Section A\n </span>\n </h2>\n \n </div>\n <div id=\"one-section-open-example-content-1\" class=\"govuk-accordion__section-content\" aria-labelledby=\"one-section-open-example-heading-1\">\n <ul class=\"govuk-list govuk-list--bullet\">\n <li>Example item 1</li>\n</ul>\n\n </div>\n </div>\n \n \n \n <div class=\"govuk-accordion__section \">\n <div class=\"govuk-accordion__section-header\">\n <h2 class=\"govuk-accordion__section-heading\">\n <span class=\"govuk-accordion__section-button\" id=\"one-section-open-example-heading-2\">\n Section B\n </span>\n </h2>\n \n </div>\n <div id=\"one-section-open-example-content-2\" class=\"govuk-accordion__section-content\" aria-labelledby=\"one-section-open-example-heading-2\">\n <ul class=\"govuk-list govuk-list--bullet\">\n <li>Example item 2</li>\n</ul>\n\n </div>\n </div>\n \n \n</div>"
85
+ },
86
+ {
87
+ "name": "with all sections already open",
88
+ "options": {
89
+ "id": "all-sections-open-example",
90
+ "items": [
91
+ {
92
+ "heading": {
93
+ "text": "Section A"
94
+ },
95
+ "expanded": true,
96
+ "content": {
97
+ "html": "<ul class=\"govuk-list govuk-list--bullet\">\n <li>Example item 1</li>\n</ul>\n"
98
+ }
99
+ },
100
+ {
101
+ "heading": {
102
+ "text": "Section B"
103
+ },
104
+ "expanded": true,
105
+ "content": {
106
+ "html": "<ul class=\"govuk-list govuk-list--bullet\">\n <li>Example item 2</li>\n</ul>\n"
107
+ }
108
+ }
109
+ ]
110
+ },
111
+ "html": "<div class=\"govuk-accordion\" data-module=\"govuk-accordion\" id=\"all-sections-open-example\">\n \n \n <div class=\"govuk-accordion__section govuk-accordion__section--expanded\">\n <div class=\"govuk-accordion__section-header\">\n <h2 class=\"govuk-accordion__section-heading\">\n <span class=\"govuk-accordion__section-button\" id=\"all-sections-open-example-heading-1\">\n Section A\n </span>\n </h2>\n \n </div>\n <div id=\"all-sections-open-example-content-1\" class=\"govuk-accordion__section-content\" aria-labelledby=\"all-sections-open-example-heading-1\">\n <ul class=\"govuk-list govuk-list--bullet\">\n <li>Example item 1</li>\n</ul>\n\n </div>\n </div>\n \n \n \n <div class=\"govuk-accordion__section govuk-accordion__section--expanded\">\n <div class=\"govuk-accordion__section-header\">\n <h2 class=\"govuk-accordion__section-heading\">\n <span class=\"govuk-accordion__section-button\" id=\"all-sections-open-example-heading-2\">\n Section B\n </span>\n </h2>\n \n </div>\n <div id=\"all-sections-open-example-content-2\" class=\"govuk-accordion__section-content\" aria-labelledby=\"all-sections-open-example-heading-2\">\n <ul class=\"govuk-list govuk-list--bullet\">\n <li>Example item 2</li>\n</ul>\n\n </div>\n </div>\n \n \n</div>"
112
+ },
113
+ {
114
+ "name": "with focusable elements inside",
115
+ "options": {
116
+ "id": "with-focusable-elements",
117
+ "items": [
118
+ {
119
+ "heading": {
120
+ "text": "Section A"
121
+ },
122
+ "content": {
123
+ "html": "<a class=\"govuk-link\" href=\"#\">Link A</a>"
124
+ }
125
+ },
126
+ {
127
+ "heading": {
128
+ "text": "Section B"
129
+ },
130
+ "content": {
131
+ "html": "<a class=\"govuk-link\" href=\"#\">Link B</a>"
132
+ }
133
+ }
134
+ ]
135
+ },
136
+ "html": "<div class=\"govuk-accordion\" data-module=\"govuk-accordion\" id=\"with-focusable-elements\">\n \n \n <div class=\"govuk-accordion__section \">\n <div class=\"govuk-accordion__section-header\">\n <h2 class=\"govuk-accordion__section-heading\">\n <span class=\"govuk-accordion__section-button\" id=\"with-focusable-elements-heading-1\">\n Section A\n </span>\n </h2>\n \n </div>\n <div id=\"with-focusable-elements-content-1\" class=\"govuk-accordion__section-content\" aria-labelledby=\"with-focusable-elements-heading-1\">\n <a class=\"govuk-link\" href=\"#\">Link A</a>\n </div>\n </div>\n \n \n \n <div class=\"govuk-accordion__section \">\n <div class=\"govuk-accordion__section-header\">\n <h2 class=\"govuk-accordion__section-heading\">\n <span class=\"govuk-accordion__section-button\" id=\"with-focusable-elements-heading-2\">\n Section B\n </span>\n </h2>\n \n </div>\n <div id=\"with-focusable-elements-content-2\" class=\"govuk-accordion__section-content\" aria-labelledby=\"with-focusable-elements-heading-2\">\n <a class=\"govuk-link\" href=\"#\">Link B</a>\n </div>\n </div>\n \n \n</div>"
137
+ },
138
+ {
139
+ "name": "classes",
140
+ "options": {
141
+ "classes": "myClass",
142
+ "items": [
143
+ {
144
+ "heading": {
145
+ "text": "Section A"
146
+ },
147
+ "content": {
148
+ "text": "Some content"
149
+ }
150
+ }
151
+ ]
152
+ },
153
+ "html": "<div class=\"govuk-accordion myClass\" data-module=\"govuk-accordion\" id=\"\">\n \n \n <div class=\"govuk-accordion__section \">\n <div class=\"govuk-accordion__section-header\">\n <h2 class=\"govuk-accordion__section-heading\">\n <span class=\"govuk-accordion__section-button\" id=\"-heading-1\">\n Section A\n </span>\n </h2>\n \n </div>\n <div id=\"-content-1\" class=\"govuk-accordion__section-content\" aria-labelledby=\"-heading-1\">\n Some content\n </div>\n </div>\n \n \n</div>"
154
+ },
155
+ {
156
+ "name": "attributes",
157
+ "options": {
158
+ "attributes": {
159
+ "data-attribute": "value"
160
+ },
161
+ "items": [
162
+ {
163
+ "heading": {
164
+ "text": "Section A"
165
+ },
166
+ "content": {
167
+ "text": "Some content"
168
+ }
169
+ }
170
+ ]
171
+ },
172
+ "html": "<div class=\"govuk-accordion\" data-module=\"govuk-accordion\" id=\"\" data-attribute=\"value\">\n \n \n <div class=\"govuk-accordion__section \">\n <div class=\"govuk-accordion__section-header\">\n <h2 class=\"govuk-accordion__section-heading\">\n <span class=\"govuk-accordion__section-button\" id=\"-heading-1\">\n Section A\n </span>\n </h2>\n \n </div>\n <div id=\"-content-1\" class=\"govuk-accordion__section-content\" aria-labelledby=\"-heading-1\">\n Some content\n </div>\n </div>\n \n \n</div>"
173
+ },
174
+ {
175
+ "name": "custom heading level",
176
+ "options": {
177
+ "headingLevel": 3,
178
+ "items": [
179
+ {
180
+ "heading": {
181
+ "text": "Section A"
182
+ },
183
+ "content": {
184
+ "text": "Some content"
185
+ }
186
+ }
187
+ ]
188
+ },
189
+ "html": "<div class=\"govuk-accordion\" data-module=\"govuk-accordion\" id=\"\">\n \n \n <div class=\"govuk-accordion__section \">\n <div class=\"govuk-accordion__section-header\">\n <h3 class=\"govuk-accordion__section-heading\">\n <span class=\"govuk-accordion__section-button\" id=\"-heading-1\">\n Section A\n </span>\n </h3>\n \n </div>\n <div id=\"-content-1\" class=\"govuk-accordion__section-content\" aria-labelledby=\"-heading-1\">\n Some content\n </div>\n </div>\n \n \n</div>"
190
+ },
191
+ {
192
+ "name": "heading html",
193
+ "options": {
194
+ "items": [
195
+ {
196
+ "heading": {
197
+ "html": "<span class=\"myClass\">Section A</span>"
198
+ },
199
+ "content": {
200
+ "text": "Some content"
201
+ }
202
+ }
203
+ ]
204
+ },
205
+ "html": "<div class=\"govuk-accordion\" data-module=\"govuk-accordion\" id=\"\">\n \n \n <div class=\"govuk-accordion__section \">\n <div class=\"govuk-accordion__section-header\">\n <h2 class=\"govuk-accordion__section-heading\">\n <span class=\"govuk-accordion__section-button\" id=\"-heading-1\">\n <span class=\"myClass\">Section A</span>\n </span>\n </h2>\n \n </div>\n <div id=\"-content-1\" class=\"govuk-accordion__section-content\" aria-labelledby=\"-heading-1\">\n Some content\n </div>\n </div>\n \n \n</div>"
206
+ },
207
+ {
208
+ "name": "with falsey values",
209
+ "options": {
210
+ "items": [
211
+ {
212
+ "heading": {
213
+ "text": "Section A"
214
+ },
215
+ "content": {
216
+ "text": "Some content"
217
+ }
218
+ },
219
+ false,
220
+ "",
221
+ null,
222
+ {
223
+ "heading": {
224
+ "text": "Section B"
225
+ },
226
+ "content": {
227
+ "text": "Some content"
228
+ }
229
+ }
230
+ ]
231
+ },
232
+ "html": "<div class=\"govuk-accordion\" data-module=\"govuk-accordion\" id=\"\">\n \n \n <div class=\"govuk-accordion__section \">\n <div class=\"govuk-accordion__section-header\">\n <h2 class=\"govuk-accordion__section-heading\">\n <span class=\"govuk-accordion__section-button\" id=\"-heading-1\">\n Section A\n </span>\n </h2>\n \n </div>\n <div id=\"-content-1\" class=\"govuk-accordion__section-content\" aria-labelledby=\"-heading-1\">\n Some content\n </div>\n </div>\n \n \n \n \n \n \n \n \n \n <div class=\"govuk-accordion__section \">\n <div class=\"govuk-accordion__section-header\">\n <h2 class=\"govuk-accordion__section-heading\">\n <span class=\"govuk-accordion__section-button\" id=\"-heading-5\">\n Section B\n </span>\n </h2>\n \n </div>\n <div id=\"-content-5\" class=\"govuk-accordion__section-content\" aria-labelledby=\"-heading-5\">\n Some content\n </div>\n </div>\n \n \n</div>"
233
+ }
234
+ ]
235
+ }