@ons/design-system 72.10.5 → 72.10.7

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.
Files changed (57) hide show
  1. package/components/button/_button.scss +8 -6
  2. package/components/char-check-limit/_macro.njk +5 -4
  3. package/components/char-check-limit/_macro.spec.js +167 -7
  4. package/components/char-check-limit/character-check.js +23 -17
  5. package/components/char-check-limit/character-check.spec.js +106 -1
  6. package/components/chart/_chart.scss +33 -5
  7. package/components/chart/_macro.njk +172 -140
  8. package/components/chart/_macro.spec.js +378 -22
  9. package/components/chart/annotations-options.js +1 -1
  10. package/components/chart/bar-chart.js +1 -0
  11. package/components/chart/chart-iframe-resize.dom.js +8 -0
  12. package/components/chart/chart-iframe-resize.js +16 -0
  13. package/components/chart/chart.js +5 -0
  14. package/components/chart/example-area-chart-with-axis-min-and-max-values.njk +72 -0
  15. package/components/chart/example-bar-chart-with-axis-min-and-max-values.njk +59 -0
  16. package/components/chart/example-bar-chart.njk +4 -0
  17. package/components/chart/example-column-chart-with-axis-min-and-max-values.njk +59 -0
  18. package/components/chart/example-iframe-chart.njk +32 -0
  19. package/components/chart/example-line-chart-with-annotations.njk +3 -1
  20. package/components/chart/example-line-chart-with-axis-min-and-max-values.njk +227 -0
  21. package/components/chart/example-line-chart.njk +4 -0
  22. package/components/chart/example-scatter-chart-with-axis-min-and-max-values.njk +98 -0
  23. package/components/chart/example-scatter-chart.njk +4 -0
  24. package/components/chart/range-annotations-options.js +1 -1
  25. package/components/chart/reference-line-annotations-options.js +1 -1
  26. package/components/chart/specific-chart-options.js +19 -0
  27. package/components/checkboxes/_macro.spec.js +3 -3
  28. package/components/details-panel/_details-panel.scss +4 -0
  29. package/components/details-panel/_macro.njk +17 -13
  30. package/components/details-panel/_macro.spec.js +17 -0
  31. package/components/details-panel/example-details-panel-open.njk +2 -1
  32. package/components/details-panel/example-details-panel.njk +2 -1
  33. package/components/header/_header.scss +40 -24
  34. package/components/header/_macro.njk +103 -89
  35. package/components/header/_macro.spec.js +130 -2
  36. package/components/header/example-header-basic-with-search-and-language.njk +207 -0
  37. package/components/header/{example-header-with-search-button.njk → example-header-basic-with-search-button.njk} +1 -0
  38. package/components/header/example-header-basic.njk +1 -0
  39. package/components/hero/_macro.njk +9 -2
  40. package/components/hero/_macro.spec.js +22 -0
  41. package/components/hero/example-hero-grey.njk +2 -1
  42. package/components/input/_macro.njk +1 -2
  43. package/components/input/_macro.spec.js +2 -22
  44. package/components/input/example-input-search-with-character-check.njk +0 -1
  45. package/components/language-selector/_macro.njk +1 -1
  46. package/components/language-selector/_macro.spec.js +45 -0
  47. package/components/navigation/navigation.js +24 -17
  48. package/components/pagination/_macro.njk +17 -7
  49. package/components/pagination/_macro.spec.js +191 -17
  50. package/components/textarea/_macro.njk +19 -3
  51. package/components/textarea/_macro.spec.js +76 -3
  52. package/components/textarea/example-textarea-with-word-limit.njk +20 -0
  53. package/css/main.css +1 -1
  54. package/js/main.js +2 -0
  55. package/package.json +3 -2
  56. package/scripts/main.es5.js +3 -1
  57. package/scripts/main.js +3 -1
@@ -65,6 +65,15 @@
65
65
  margin: 0 0 1rem;
66
66
  }
67
67
  }
68
+
69
+ &__language {
70
+ display: none;
71
+
72
+ .ons-js-enabled & {
73
+ display: block;
74
+ }
75
+ }
76
+
68
77
  // Modifier - variants
69
78
  &--description {
70
79
  .ons-header {
@@ -169,13 +178,13 @@
169
178
  }
170
179
 
171
180
  &__org-logo--large {
172
- @include mq('2xs', 460px) {
181
+ @include mq('2xs', 590px) {
173
182
  display: none;
174
183
  }
175
184
  }
176
185
 
177
186
  &__org-logo--small {
178
- @include mq(461px) {
187
+ @include mq(591px) {
179
188
  display: none;
180
189
  }
181
190
  }
@@ -245,6 +254,16 @@
245
254
 
246
255
  #{$root}__menu-links {
247
256
  width: 100%;
257
+
258
+ #{$root}__language {
259
+ display: block;
260
+ padding-top: 1rem;
261
+
262
+ // hide the language switcher within nav when js is enabled
263
+ .ons-js-enabled & {
264
+ display: none;
265
+ }
266
+ }
248
267
  }
249
268
 
250
269
  // When JS is enabled, revert the no-js styles
@@ -260,26 +279,11 @@
260
279
  }
261
280
 
262
281
  &-nav-menu {
263
- // applies styles for non-js variant
264
- background-color: var(--ons-color-branded-tint);
265
- border-bottom: 1px solid var(--ons-color-ocean-blue);
266
282
  margin-bottom: 0;
267
- padding-bottom: 1rem;
283
+ padding-bottom: 2.5rem;
268
284
  position: relative;
269
285
  width: 100%;
270
286
 
271
- // updates styles when js is enabled
272
- .ons-js-enabled & {
273
- border-bottom: 0;
274
- margin-bottom: 1rem;
275
- padding-bottom: 0;
276
- position: absolute;
277
- top: 100%;
278
- left: 50%;
279
- width: 100vw;
280
- transform: translateX(-50%);
281
- }
282
-
283
287
  &__key-list {
284
288
  border-bottom: 1px solid var(--ons-color-ocean-blue);
285
289
  margin-bottom: 1.25rem;
@@ -312,14 +316,14 @@
312
316
  }
313
317
  }
314
318
 
319
+ // applies styles for non-js variant
320
+ &-nav-menu ~ &-nav-search {
321
+ border-top: 1px solid var(--ons-color-ocean-blue);
322
+ }
323
+
324
+ &-nav-menu,
315
325
  &-nav-search {
316
326
  background-color: var(--ons-color-branded-tint);
317
- margin-bottom: 1rem;
318
- @extend .ons-u-pt-2xl;
319
- @extend .ons-u-pb-2xl;
320
-
321
- position: relative;
322
- width: 100%;
323
327
 
324
328
  // updates styles when js is enabled
325
329
  .ons-js-enabled & {
@@ -328,7 +332,19 @@
328
332
  left: 50%;
329
333
  width: 100vw;
330
334
  transform: translateX(-50%);
335
+ border-top: 0;
336
+ z-index: 500;
331
337
  }
338
+ }
339
+
340
+ &__menu-links ~ &__links {
341
+ padding-bottom: 0.25rem;
342
+ }
343
+
344
+ &-nav-search {
345
+ @extend .ons-u-pt-2xl;
346
+ @extend .ons-u-pb-2xl;
347
+
332
348
  &__input {
333
349
  border-bottom: 1px solid var(--ons-color-ocean-blue);
334
350
  @extend .ons-u-mb-2xl;
@@ -7,6 +7,7 @@
7
7
  {% set openingTag = "<" + titleTag %}
8
8
  {% set closingTag = "</" + titleTag + ">" %}
9
9
  {% set currentLanguageIsoCode = "en" %}
10
+ {% set logoAltText = params.mastheadLogoAltText or params.mastheadLogo.altText %}
10
11
 
11
12
  {% if params.language and params.language.languages %}
12
13
  {% set currentLanguage = params.language.languages | selectattr("current") | first %}
@@ -42,7 +43,6 @@
42
43
  >
43
44
  <div class="ons-grid__col ons-col-auto">
44
45
  {%- if not params.mastheadLogo.multipleLogos -%}
45
-
46
46
  {% set mastheadLogo %}
47
47
  <div class="ons-header__org-logo ons-header__org-logo--large">
48
48
  {% if params.mastheadLogo.large %}
@@ -51,7 +51,7 @@
51
51
  {{-
52
52
  onsIcon({
53
53
  "iconType": 'ons-logo-' + currentLanguageIsoCode,
54
- "altText": 'Office for National Statistics homepage'
54
+ "altText": logoAltText | default('Office for National Statistics logo')
55
55
  })
56
56
  -}}
57
57
  {% endif %}
@@ -65,7 +65,7 @@
65
65
  {{-
66
66
  onsIcon({
67
67
  "iconType": 'ons-logo-stacked-' + currentLanguageIsoCode,
68
- "altText": 'Office for National Statistics logo'
68
+ "altText": logoAltText | default('Office for National Statistics logo')
69
69
  })
70
70
  -}}
71
71
  {% endif %}
@@ -88,7 +88,7 @@
88
88
  {{-
89
89
  onsIcon({
90
90
  "iconType": 'ons-logo-stacked-' + currentLanguageIsoCode,
91
- "altText": 'Office for National Statistics logo'
91
+ "altText": logoAltText | default('Office for National Statistics logo')
92
92
  })
93
93
  -}}
94
94
  {% endif %}
@@ -102,86 +102,9 @@
102
102
  </div>
103
103
  {%- endif -%}
104
104
  </div>
105
- {% if params.language or params.serviceLinks %}
106
- <div class="ons-header__links ons-grid__col ons-u-ml-auto">
107
- {% if params.language %}
108
- <div class="ons-grid__col ons-col-auto{{ ' ons-u-mr-s ons-u-d-no@2xs@xs' if params.serviceLinks }}">
109
- {% from "components/language-selector/_macro.njk" import onsLanguageSelector %}
110
- {{ onsLanguageSelector(params.language) }}
111
- </div>
112
- {% endif %}
113
- {% if params.serviceLinks %}
114
- {% if params.serviceLinks.itemsList | length == 1 and params.language %}
115
- {% set breakpoint = 'xs' %}
116
- {% set controlVisibility = true %}
117
- {% elif params.serviceLinks.itemsList | length > 1 %}
118
- {% set breakpoint = 'm' %}
119
- {% set controlVisibility = true %}
120
- {% else %}
121
- {% set controlVisibility = false %}
122
- {% endif %}
123
- <div
124
- class="ons-grid__col ons-col-auto{% if controlVisibility == true %}{{ ' ' }}ons-u-d-no@2xs@{{ breakpoint }}{% endif %}"
125
- >
126
- <nav
127
- class="ons-header-service-nav ons-header-service-nav--main{{ ' ' + params.serviceLinks.classes if params.serviceLinks.classes else '' }}"
128
- aria-label="{{ params.serviceLinks.ariaLabel | default('Service links navigation') }}"
129
- >
130
- <ul class="ons-header-service-nav__list">
131
- {% for item in params.serviceLinks.itemsList %}
132
- <li class="ons-header-service-nav__item">
133
- {% if item.iconType %}
134
- {{-
135
- onsIcon({
136
- "iconType": item.iconType
137
- })
138
- -}}
139
- {% endif %}
140
- {% if item.url %}
141
- <a
142
- href="{{ item.url }}"
143
- class="ons-header-service-nav__link"
144
- {% if item.id %}id="{{ item.id }}"{% endif %}
145
- >{% if item.title %}{{ item.title }}{% elif item.text %}{{ item.text }}{% endif %}</a
146
- >
147
- {% else %}
148
- {% if item.title %}{{ item.title }}{% elif item.text %}{{ item.text }}{% endif %}
149
- {% endif %}
150
- </li>
151
- {% endfor %}
152
- </ul>
153
- </nav>
154
- </div>
155
- {% if params.serviceLinks.itemsList | length > 1 or params.language %}
156
- {% if params.variants == 'internal' %}
157
- {% set buttonVariant = ["mobile", "text-link", "text-link-inverse"] %}
158
- {% elif params.variants == 'neutral' %}
159
- {% set buttonVariant = ["mobile", "neutral"] %}
160
- {% else %}
161
- {% set buttonVariant = ["mobile", "text-link"] %}
162
- {% endif %}
163
- <div class="ons-grid__col ons-col-auto ons-u-d-no@{{ breakpoint }}">
164
- {{
165
- onsButton({
166
- "text": params.serviceLinks.toggleServicesButton.text | default("Account"),
167
- "classes": "ons-u-d-no ons-js-toggle-services",
168
- "type": "button",
169
- "variants": buttonVariant,
170
- "attributes": {
171
- "aria-label": params.serviceLinks.toggleServicesButton.ariaLabel | default("Toggle menu"),
172
- "aria-controls": params.serviceLinks.id,
173
- "aria-expanded": "false"
174
- }
175
- })
176
- }}
177
- </div>
178
- {% endif %}
179
- {% endif %}
180
- </div>
181
- {% endif %}
182
105
 
183
106
  {% if params.variants == "basic" %}
184
- <div class="ons-grid__col ons-col-auto ons-header__menu-links">
107
+ <div class="ons-grid__col ons-col-auto ons-header__menu-links ons-u-ml-auto">
185
108
  {% if params.menuLinks %}
186
109
  <div class="ons-header__links ons-grid__col">
187
110
  {{
@@ -203,6 +126,15 @@
203
126
  </div>
204
127
  {% endif %}
205
128
 
129
+ {% if params.language %}
130
+ <div class="ons-grid__col ons-col-auto{{ ' ons-u-mr-s ons-u-d-no@2xs@xs' if params.serviceLinks }}">
131
+ <div class="ons-header__language">
132
+ {% from "components/language-selector/_macro.njk" import onsLanguageSelector %}
133
+ {{ onsLanguageSelector(params.language) }}
134
+ </div>
135
+ </div>
136
+ {% endif %}
137
+
206
138
  {% if params.variants == "basic" and params.menuLinks %}
207
139
  <nav
208
140
  class="ons-js-nav-menu ons-header-nav-menu ons-u-pt-2xl"
@@ -318,15 +250,14 @@
318
250
  "id": 'search-field',
319
251
  "width": 'full',
320
252
  "label": {
321
- "text": 'Search the ONS',
253
+ "text": params.searchLinks.searchNavigationInputLabel | default('Search the ONS'),
322
254
  "id": "header-search-input-label"
323
255
  },
324
256
  "searchButton": {
325
257
  "visuallyHideButtonText": true,
326
- "text": 'Search',
258
+ "text": params.searchLinks.searchNavigationButtonText | default('Search'),
327
259
  "iconType": 'search',
328
260
  'variant': 'header'
329
-
330
261
  }
331
262
  })
332
263
  }}
@@ -361,6 +292,87 @@
361
292
  {% endif %}
362
293
  </div>
363
294
  {% endif %}
295
+ {% if params.language or params.serviceLinks %}
296
+ <div
297
+ class="ons-header__links ons-grid__col{{ ' ons-u-ml-auto' if not params.searchLinks and not params.menuLinks }}"
298
+ >
299
+ {% if params.language %}
300
+ <div class="ons-grid__col ons-col-auto{{ ' ons-u-mr-s ons-u-d-no@2xs@xs' if params.serviceLinks }}">
301
+ <div class="ons-header__language">
302
+ {% from "components/language-selector/_macro.njk" import onsLanguageSelector %}
303
+ {{ onsLanguageSelector(params.language) }}
304
+ </div>
305
+ </div>
306
+ {% endif %}
307
+ {% if params.serviceLinks %}
308
+ {% if params.serviceLinks.itemsList | length == 1 and params.language %}
309
+ {% set breakpoint = 'xs' %}
310
+ {% set controlVisibility = true %}
311
+ {% elif params.serviceLinks.itemsList | length > 1 %}
312
+ {% set breakpoint = 'm' %}
313
+ {% set controlVisibility = true %}
314
+ {% else %}
315
+ {% set controlVisibility = false %}
316
+ {% endif %}
317
+ <div
318
+ class="ons-grid__col ons-col-auto{% if controlVisibility == true %}{{ ' ' }}ons-u-d-no@2xs@{{ breakpoint }}{% endif %}"
319
+ >
320
+ <nav
321
+ class="ons-header-service-nav ons-header-service-nav--main{{ ' ' + params.serviceLinks.classes if params.serviceLinks.classes else '' }}"
322
+ aria-label="{{ params.serviceLinks.ariaLabel | default('Service links navigation') }}"
323
+ >
324
+ <ul class="ons-header-service-nav__list">
325
+ {% for item in params.serviceLinks.itemsList %}
326
+ <li class="ons-header-service-nav__item">
327
+ {% if item.iconType %}
328
+ {{-
329
+ onsIcon({
330
+ "iconType": item.iconType
331
+ })
332
+ -}}
333
+ {% endif %}
334
+ {% if item.url %}
335
+ <a
336
+ href="{{ item.url }}"
337
+ class="ons-header-service-nav__link"
338
+ {% if item.id %}id="{{ item.id }}"{% endif %}
339
+ >{% if item.title %}{{ item.title }}{% elif item.text %}{{ item.text }}{% endif %}</a
340
+ >
341
+ {% else %}
342
+ {% if item.title %}{{ item.title }}{% elif item.text %}{{ item.text }}{% endif %}
343
+ {% endif %}
344
+ </li>
345
+ {% endfor %}
346
+ </ul>
347
+ </nav>
348
+ </div>
349
+ {% if params.serviceLinks.itemsList | length > 1 or params.language %}
350
+ {% if params.variants == 'internal' %}
351
+ {% set buttonVariant = ["mobile", "text-link", "text-link-inverse"] %}
352
+ {% elif params.variants == 'neutral' %}
353
+ {% set buttonVariant = ["mobile", "neutral"] %}
354
+ {% else %}
355
+ {% set buttonVariant = ["mobile", "text-link"] %}
356
+ {% endif %}
357
+ <div class="ons-grid__col ons-col-auto ons-u-d-no@{{ breakpoint }}">
358
+ {{
359
+ onsButton({
360
+ "text": params.serviceLinks.toggleServicesButton.text | default("Account"),
361
+ "classes": "ons-u-d-no ons-js-toggle-services",
362
+ "type": "button",
363
+ "variants": buttonVariant,
364
+ "attributes": {
365
+ "aria-label": params.serviceLinks.toggleServicesButton.ariaLabel | default("Toggle menu"),
366
+ "aria-controls": params.serviceLinks.id,
367
+ "aria-expanded": "false"
368
+ }
369
+ })
370
+ }}
371
+ </div>
372
+ {% endif %}
373
+ {% endif %}
374
+ </div>
375
+ {% endif %}
364
376
  </div>
365
377
  </div>
366
378
  {% if params.serviceLinks %}
@@ -393,8 +405,10 @@
393
405
  {% endfor %}
394
406
  </ul>
395
407
  {% if params.language %}
396
- {% from "components/language-selector/_macro.njk" import onsLanguageSelector %}
397
- {{ onsLanguageSelector(params.language) }}
408
+ <div class="ons-header__language">
409
+ {% from "components/language-selector/_macro.njk" import onsLanguageSelector %}
410
+ {{ onsLanguageSelector(params.language) }}
411
+ </div>
398
412
  {% endif %}
399
413
  </nav>
400
414
  {% endif %}
@@ -478,13 +492,13 @@
478
492
  <span class="ons-grid ons-u-d-no@2xs@xs ons-u-ml-no ons-u-d-no@l">
479
493
  {{
480
494
  onsButton({
481
- "text": "Search",
495
+ "text": params.searchLinks.searchNavigationButtonText | default('Search'),
482
496
  "classes": "ons-btn--search ons-u-ml-2xs ons-u-d-no ons-js-toggle-search",
483
497
  "variants": buttonVariant,
484
498
  "iconType": "search",
485
499
  "iconPosition": "only",
486
500
  "attributes": {
487
- "aria-label": "Toggle search" ,
501
+ "aria-label": params.searchLinks.searchNavigationButtonAriaLabel | default('Toggle search'),
488
502
  "aria-controls": "ons-site-search",
489
503
  "aria-expanded": "false"
490
504
  }
@@ -106,7 +106,7 @@ describe('FOR: Macro: Header', () => {
106
106
  expect(iconsSpy.occurrences[0].iconType).toBe('ons-logo-en');
107
107
  });
108
108
  test('THEN: renders logo with correct default alt-text on large screen', () => {
109
- expect(iconsSpy.occurrences[0].altText).toBe('Office for National Statistics homepage');
109
+ expect(iconsSpy.occurrences[0].altText).toBe('Office for National Statistics logo');
110
110
  });
111
111
  test('THEN: renders default small logo on small screen', () => {
112
112
  expect(iconsSpy.occurrences[1].iconType).toBe('ons-logo-stacked-en');
@@ -153,6 +153,30 @@ describe('FOR: Macro: Header', () => {
153
153
  });
154
154
  });
155
155
  });
156
+ describe('GIVEN: Params: mastheadLogoAltText', () => {
157
+ describe('WHEN: mastheadLogoAltText is provided', () => {
158
+ const faker = templateFaker();
159
+ const iconsSpy = faker.spy('icon');
160
+ faker.renderComponent('header', {
161
+ ...EXAMPLE_HEADER_BASIC,
162
+ mastheadLogoAltText: 'Custom alt text for logo',
163
+ });
164
+ test('THEN: renders logo with provided alt text', () => {
165
+ expect(iconsSpy.occurrences[0].altText).toBe('Custom alt text for logo');
166
+ });
167
+ });
168
+ describe('WHEN: mastheadLogoAltText is not provided', () => {
169
+ const faker = templateFaker();
170
+ const iconsSpy = faker.spy('icon');
171
+ faker.renderComponent('header', {
172
+ ...EXAMPLE_HEADER_BASIC,
173
+ mastheadLogoAltText: undefined,
174
+ });
175
+ test('THEN: renders logo with default alt text', () => {
176
+ expect(iconsSpy.occurrences[0].altText).toBe('Office for National Statistics logo');
177
+ });
178
+ });
179
+ });
156
180
  describe('GIVEN: Params: multipleLogos', () => {
157
181
  describe('WHEN: image parameter is set to "ONS Logo"', () => {
158
182
  const faker = templateFaker();
@@ -803,7 +827,7 @@ describe('FOR: Macro: Header', () => {
803
827
  attributes: {
804
828
  'aria-controls': 'search-links-id',
805
829
  'aria-expanded': 'true',
806
- 'aria-label': 'Example aria label',
830
+ 'aria-label': 'Custom search button aria label',
807
831
  'aria-disabled': 'true',
808
832
  },
809
833
  });
@@ -901,6 +925,110 @@ describe('FOR: Macro: Header', () => {
901
925
  expect($searchBtn.attr('aria-disabled')).toBe('true');
902
926
  });
903
927
  });
928
+
929
+ describe('WHEN: searchLinks are provided with all custom properties', () => {
930
+ const faker = templateFaker();
931
+ const buttonSpy = faker.spy('button', { suppressOutput: true });
932
+ faker.renderComponent('header', { ...EXAMPLE_HEADER_SEARCH_LINKS, variants: 'basic' });
933
+ test('THEN: renders search icon button with custom aria-label', () => {
934
+ expect(buttonSpy.occurrences[0]).toBeDefined();
935
+ expect(buttonSpy.occurrences[0].attributes['aria-label']).toBe('Custom search button aria label');
936
+ });
937
+ });
938
+ describe('WHEN: searchButtonAriaLabel is not provided', () => {
939
+ const faker = templateFaker();
940
+ const buttonSpy = faker.spy('button', { suppressOutput: true });
941
+ faker.renderComponent('header', {
942
+ ...EXAMPLE_HEADER_SEARCH_LINKS,
943
+ searchLinks: {
944
+ ...EXAMPLE_HEADER_SEARCH_LINKS.searchLinks,
945
+ searchButtonAriaLabel: undefined,
946
+ },
947
+ variants: 'basic',
948
+ });
949
+ test('THEN: renders search icon button with default aria-label', () => {
950
+ expect(buttonSpy.occurrences[0]).toBeDefined();
951
+ expect(buttonSpy.occurrences[0].attributes['aria-label']).toBe('Toggle search');
952
+ });
953
+ });
954
+ describe('WHEN: searchNavigationButtonAriaLabel is provided', () => {
955
+ const faker = templateFaker();
956
+ const buttonSpy = faker.spy('button', { suppressOutput: true });
957
+ faker.renderComponent('header', {
958
+ ...EXAMPLE_HEADER_SEARCH_LINKS,
959
+ siteSearchAutosuggest: {},
960
+ });
961
+ test('THEN: renders search navigation button with custom aria-label', () => {
962
+ const found = buttonSpy.occurrences.find(
963
+ (btn) => btn.attributes && btn.attributes['aria-label'] === 'Custom search nav button aria label',
964
+ );
965
+ expect(found).toBeDefined();
966
+ });
967
+ });
968
+ describe('WHEN: searchNavigationButtonAriaLabel is not provided', () => {
969
+ const faker = templateFaker();
970
+ const buttonSpy = faker.spy('button', { suppressOutput: true });
971
+ faker.renderComponent('header', {
972
+ ...EXAMPLE_HEADER_SEARCH_LINKS,
973
+ searchLinks: {
974
+ ...EXAMPLE_HEADER_SEARCH_LINKS.searchLinks,
975
+ searchNavigationButtonAriaLabel: undefined,
976
+ },
977
+ siteSearchAutosuggest: {},
978
+ });
979
+ test('THEN: renders search navigation button with default aria-label', () => {
980
+ const found = buttonSpy.occurrences.find((btn) => btn.attributes && btn.attributes['aria-label'] === 'Toggle search');
981
+ expect(found).toBeDefined();
982
+ });
983
+ });
984
+ describe('WHEN: searchNavigationInputLabel is provided', () => {
985
+ const $ = cheerio.load(renderComponent('header', { ...EXAMPLE_HEADER_SEARCH_LINKS, variants: 'basic' }));
986
+ test('THEN: renders search input with custom label', () => {
987
+ expect($('#header-search-input-label').text().trim()).toBe('Custom search input label');
988
+ });
989
+ });
990
+ describe('WHEN: searchNavigationInputLabel is not provided', () => {
991
+ const $ = cheerio.load(
992
+ renderComponent('header', {
993
+ ...EXAMPLE_HEADER_SEARCH_LINKS,
994
+ searchLinks: {
995
+ ...EXAMPLE_HEADER_SEARCH_LINKS.searchLinks,
996
+ searchNavigationInputLabel: undefined,
997
+ },
998
+ variants: 'basic',
999
+ }),
1000
+ );
1001
+ test('THEN: renders search input with default label', () => {
1002
+ expect($('#header-search-input-label').text().trim()).toBe('Search the ONS');
1003
+ });
1004
+ });
1005
+ describe('WHEN: searchNavigationButtonText is provided', () => {
1006
+ const $ = cheerio.load(renderComponent('header', { ...EXAMPLE_HEADER_SEARCH_LINKS, variants: 'basic' }));
1007
+
1008
+ test('THEN: renders the visually hidden search navigation button text', () => {
1009
+ const $button = $('.ons-search__btn.ons-btn--header-search');
1010
+ const hiddenText = $button.find('.ons-u-vh').text().trim();
1011
+ expect(hiddenText).toBe(EXAMPLE_HEADER_SEARCH_LINKS.searchLinks.searchNavigationButtonText);
1012
+ });
1013
+ });
1014
+ describe('WHEN: searchNavigationButtonText is not provided', () => {
1015
+ const $ = cheerio.load(
1016
+ renderComponent('header', {
1017
+ ...EXAMPLE_HEADER_SEARCH_LINKS,
1018
+ searchLinks: {
1019
+ ...EXAMPLE_HEADER_SEARCH_LINKS.searchLinks,
1020
+ searchNavigationButtonText: undefined,
1021
+ },
1022
+ variants: 'basic',
1023
+ }),
1024
+ );
1025
+
1026
+ test('THEN: renders the default fallback search navigation button text', () => {
1027
+ const $button = $('.ons-search__btn.ons-btn--header-search');
1028
+ const hiddenText = $button.find('.ons-u-vh').text().trim();
1029
+ expect(hiddenText).toBe('Search');
1030
+ });
1031
+ });
904
1032
  });
905
1033
 
906
1034
  describe('GIVEN: Params: menuLinks', () => {