@ons/design-system 72.0.1 → 72.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/components/accordion/_macro.spec.js +2 -2
- package/components/address-input/_macro.spec.js +245 -322
- package/components/address-input/autosuggest.address.spec.js +16 -14
- package/components/address-output/_macro.spec.js +121 -74
- package/components/address-output/_test_examples.js +8 -0
- package/components/autosuggest/_macro.njk +1 -0
- package/components/autosuggest/_macro.spec.js +373 -178
- package/components/autosuggest/autosuggest.spec.js +3 -1
- package/components/autosuggest/autosuggest.ui.js +39 -10
- package/components/autosuggest/example-autosuggest-country.njk +2 -1
- package/components/autosuggest/fuse-config.js +7 -2
- package/components/back-to-top/back-to-top.dom.js +4 -4
- package/components/back-to-top/back-to-top.js +1 -1
- package/components/browser-banner/_macro.spec.js +11 -11
- package/components/button/_macro.njk +1 -1
- package/components/button/_macro.spec.js +405 -351
- package/components/button/example-button-group.njk +1 -0
- package/components/checkboxes/_checkbox-macro.njk +20 -0
- package/components/checkboxes/_checkbox.scss +3 -3
- package/components/checkboxes/_macro.njk +5 -0
- package/components/checkboxes/_macro.spec.js +35 -0
- package/components/checkboxes/example-checkboxes-with-revealed-text-area-expanded.njk +68 -0
- package/components/checkboxes/example-checkboxes-with-revealed-text-area.njk +67 -0
- package/components/details/_details.scss +1 -2
- package/components/details/example-details-open.njk +10 -0
- package/components/external-link/_macro.spec.js +66 -69
- package/components/external-link/_test_examples.js +4 -0
- package/components/feedback/_macro.spec.js +109 -80
- package/components/feedback/_test_examples.js +17 -0
- package/components/field/_macro.spec.js +106 -69
- package/components/section-navigation/_macro.njk +9 -6
- package/components/summary/_macro.njk +73 -78
- package/components/summary/_macro.spec.js +5 -15
- package/components/summary/_summary.scss +16 -11
- package/components/table-of-contents/_macro.njk +3 -3
- package/components/table-of-contents/_macro.spec.js +3 -3
- package/components/table-of-contents/{_toc.scss → _table-of-contents.scss} +1 -1
- package/components/table-of-contents/table-of-contents.dom.js +13 -0
- package/components/table-of-contents/{toc.js → table-of-contents.js} +4 -4
- package/components/table-of-contents/{toc.spec.js → table-of-contents.spec.js} +2 -2
- package/components/tabs/_tabs.scss +10 -11
- package/components/tabs/tabs.js +3 -3
- package/components/timeout-modal/timeout-modal.spec.js +1 -1
- package/css/main.css +1 -1
- package/js/analytics.js +1 -1
- package/js/main.js +1 -1
- package/package.json +2 -2
- package/scripts/main.es5.js +1 -1
- package/scripts/main.js +1 -1
- package/scss/main.scss +1 -1
- package/scss/objects/_page.scss +1 -1
- package/scss/utilities/_margin.scss +4 -0
- package/scss/utilities/_padding.scss +4 -0
- package/components/table-of-contents/toc.dom.js +0 -13
|
@@ -37,6 +37,7 @@ export default class AutosuggestUI {
|
|
|
37
37
|
errorAPI,
|
|
38
38
|
errorAPILinkText,
|
|
39
39
|
typeMore,
|
|
40
|
+
customResultsThreshold,
|
|
40
41
|
}) {
|
|
41
42
|
// DOM Elements
|
|
42
43
|
this.context = context;
|
|
@@ -65,6 +66,7 @@ export default class AutosuggestUI {
|
|
|
65
66
|
this.errorAPI = errorAPI || context.getAttribute('data-error-api');
|
|
66
67
|
this.errorAPILinkText = errorAPILinkText || context.getAttribute('data-error-api-link-text');
|
|
67
68
|
this.typeMore = typeMore || context.getAttribute('data-type-more');
|
|
69
|
+
this.customResultsThreshold = customResultsThreshold || context.getAttribute('data-result-threshold');
|
|
68
70
|
this.language = context.getAttribute('data-lang');
|
|
69
71
|
this.allowMultiple = context.getAttribute('data-allow-multiple') || false;
|
|
70
72
|
this.listboxId = this.listbox.getAttribute('id');
|
|
@@ -293,9 +295,30 @@ export default class AutosuggestUI {
|
|
|
293
295
|
|
|
294
296
|
async fetchSuggestions(sanitisedQuery, data) {
|
|
295
297
|
this.abortFetch();
|
|
296
|
-
|
|
298
|
+
|
|
299
|
+
const threshold =
|
|
300
|
+
this.customResultsThreshold != null && this.customResultsThreshold >= 0 && this.customResultsThreshold <= 1
|
|
301
|
+
? this.customResultsThreshold
|
|
302
|
+
: 0.2;
|
|
303
|
+
|
|
304
|
+
let distance;
|
|
305
|
+
if (threshold >= 0.6) {
|
|
306
|
+
distance = 500;
|
|
307
|
+
} else if (threshold >= 0.4) {
|
|
308
|
+
distance = 300;
|
|
309
|
+
} else {
|
|
310
|
+
distance = 100;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const results = await runFuse(sanitisedQuery, data, this.lang, threshold, distance);
|
|
314
|
+
|
|
297
315
|
results.forEach((result) => {
|
|
298
|
-
|
|
316
|
+
const resultItem = result.item ?? result;
|
|
317
|
+
|
|
318
|
+
result.sanitisedText = sanitiseAutosuggestText(
|
|
319
|
+
resultItem[this.lang] ?? resultItem['formattedAddress'],
|
|
320
|
+
this.sanitisedQueryReplaceChars,
|
|
321
|
+
);
|
|
299
322
|
});
|
|
300
323
|
return {
|
|
301
324
|
status: this.responseStatus,
|
|
@@ -345,16 +368,18 @@ export default class AutosuggestUI {
|
|
|
345
368
|
this.listbox.innerHTML = '';
|
|
346
369
|
if (this.results) {
|
|
347
370
|
this.resultOptions = this.results.map((result, index) => {
|
|
348
|
-
|
|
371
|
+
const resultItem = result.item ?? result;
|
|
372
|
+
|
|
373
|
+
let innerHTML = this.emboldenMatch(resultItem[this.lang] ?? resultItem['formattedAddress'], this.query);
|
|
349
374
|
|
|
350
375
|
const listElement = document.createElement('li');
|
|
351
376
|
listElement.className = classAutosuggestOption;
|
|
352
377
|
listElement.setAttribute('id', `${this.listboxId}__option--${index}`);
|
|
353
378
|
listElement.setAttribute('role', 'option');
|
|
354
|
-
if (
|
|
379
|
+
if (resultItem.category) {
|
|
355
380
|
innerHTML =
|
|
356
381
|
innerHTML +
|
|
357
|
-
`<span class="ons-autosuggest__category ons-u-lighter ons-u-fs-s ons-u-db">${
|
|
382
|
+
`<span class="ons-autosuggest__category ons-u-lighter ons-u-fs-s ons-u-db">${resultItem.category}</span>`;
|
|
358
383
|
}
|
|
359
384
|
listElement.innerHTML = innerHTML;
|
|
360
385
|
listElement.addEventListener('click', () => {
|
|
@@ -485,16 +510,19 @@ export default class AutosuggestUI {
|
|
|
485
510
|
if (this.results.length) {
|
|
486
511
|
this.settingResult = true;
|
|
487
512
|
const result = this.results[index || this.highlightedResultIndex || 0];
|
|
513
|
+
const resultItem = result.item ?? result;
|
|
514
|
+
const resultValue = resultItem[this.lang] ?? resultItem['formattedAddress'];
|
|
515
|
+
|
|
488
516
|
this.resultSelected = true;
|
|
489
517
|
|
|
490
518
|
if (this.allowMultiple === 'true') {
|
|
491
|
-
let value = this.storeExistingSelections(
|
|
519
|
+
let value = this.storeExistingSelections(resultValue);
|
|
492
520
|
result.displayText = value;
|
|
493
|
-
} else if (
|
|
494
|
-
result.displayText =
|
|
495
|
-
window.location =
|
|
521
|
+
} else if (resultItem.url) {
|
|
522
|
+
result.displayText = resultValue;
|
|
523
|
+
window.location = resultItem.url;
|
|
496
524
|
} else {
|
|
497
|
-
result.displayText =
|
|
525
|
+
result.displayText = resultValue;
|
|
498
526
|
}
|
|
499
527
|
this.onSelect(result).then(() => (this.settingResult = false));
|
|
500
528
|
|
|
@@ -511,6 +539,7 @@ export default class AutosuggestUI {
|
|
|
511
539
|
const warningSpanElement = document.createElement('span');
|
|
512
540
|
const warningBodyElement = document.createElement('div');
|
|
513
541
|
|
|
542
|
+
warningContainer.id = this.listbox.getAttribute('id');
|
|
514
543
|
warningContainer.className = 'ons-autosuggest__warning';
|
|
515
544
|
warningElement.className = 'ons-panel ons-panel--warn ons-autosuggest__panel';
|
|
516
545
|
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"resultsTitleId": "country-of-birth-suggestions",
|
|
25
25
|
"autosuggestData": "/examples/data/country-of-birth.json",
|
|
26
26
|
"noResults": "No suggestions found. You can enter your own answer",
|
|
27
|
-
"typeMore": "Continue entering to get suggestions"
|
|
27
|
+
"typeMore": "Continue entering to get suggestions",
|
|
28
|
+
"resultsThreshold": 0.2
|
|
28
29
|
})
|
|
29
30
|
}}
|
|
30
31
|
</div>
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import Fuse from 'fuse.js';
|
|
2
2
|
|
|
3
|
-
export default function runFuse(query, data, searchFields) {
|
|
3
|
+
export default function runFuse(query, data, searchFields, threshold, distance) {
|
|
4
4
|
const options = {
|
|
5
5
|
shouldSort: true,
|
|
6
|
-
threshold:
|
|
6
|
+
threshold: threshold,
|
|
7
|
+
distance: distance,
|
|
7
8
|
keys: [
|
|
8
9
|
{
|
|
9
10
|
name: searchFields,
|
|
10
11
|
weight: 0.9,
|
|
11
12
|
},
|
|
13
|
+
{
|
|
14
|
+
name: 'formattedAddress',
|
|
15
|
+
weight: 0.9,
|
|
16
|
+
},
|
|
12
17
|
{
|
|
13
18
|
name: 'tags',
|
|
14
19
|
weight: 0.1,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import domready from '../../js/domready';
|
|
2
2
|
|
|
3
3
|
async function backToTop() {
|
|
4
|
-
const
|
|
4
|
+
const backToTop = [...document.querySelectorAll('.ons-js-back-to-top')];
|
|
5
5
|
|
|
6
|
-
if (
|
|
7
|
-
const
|
|
8
|
-
|
|
6
|
+
if (backToTop) {
|
|
7
|
+
const BackToTop = (await import('./back-to-top')).default;
|
|
8
|
+
backToTop.forEach((btn) => new BackToTop(btn));
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
|
|
@@ -10,22 +10,22 @@ describe('FOR: Macro: Browser-banner', () => {
|
|
|
10
10
|
describe('WHEN: params are at default state', () => {
|
|
11
11
|
const $ = cheerio.load(renderComponent('browser-banner', {}));
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
test('THEN: passes jest-axe checks', async () => {
|
|
14
14
|
const results = await axe($.html());
|
|
15
15
|
expect(results).toHaveNoViolations();
|
|
16
16
|
});
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
test('THEN: has the english default bannerLeadingText', () => {
|
|
19
19
|
const bannerLeadingText = $('.ons-browser-banner__lead').text().trim();
|
|
20
20
|
expect(bannerLeadingText).toBe('This website no longer supports your browser.');
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
test('THEN: has the english default bannerCTA', () => {
|
|
24
24
|
const bannerCtaHtml = $('.ons-browser-banner__cta').text().trim();
|
|
25
25
|
expect(bannerCtaHtml).toBe('You can upgrade your browser to the latest version.');
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
test('THEN: has the english default bannerLinkUrl', () => {
|
|
29
29
|
expect($('.ons-browser-banner__link').attr('href')).toBe('https://www.ons.gov.uk/help/browsers');
|
|
30
30
|
});
|
|
31
31
|
});
|
|
@@ -33,17 +33,17 @@ describe('FOR: Macro: Browser-banner', () => {
|
|
|
33
33
|
describe('WHEN: params are at default and language is set to welsh', () => {
|
|
34
34
|
const $ = cheerio.load(renderComponent('browser-banner', { lang: 'cy' }));
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
test('THEN: has the welsh default bannerLeadingText', () => {
|
|
37
37
|
const bannerLeadingText = $('.ons-browser-banner__lead').text().trim();
|
|
38
38
|
expect(bannerLeadingText).toBe('Nid yw’r wefan hon yn cefnogi eich porwr mwyach.');
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
test('THEN: has the welsh default bannerCTA', () => {
|
|
42
42
|
const bannerCtaHtml = $('.ons-browser-banner__cta').text().trim();
|
|
43
43
|
expect(bannerCtaHtml).toBe('Gallwch ddiweddaru eich porwr i’r fersiwn ddiweddaraf.');
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
test('THEN: has the welsh default bannerLinkUrl', () => {
|
|
47
47
|
expect($('.ons-browser-banner__link').attr('href')).toBe('https://cy.ons.gov.uk/help/browsers');
|
|
48
48
|
});
|
|
49
49
|
});
|
|
@@ -51,7 +51,7 @@ describe('FOR: Macro: Browser-banner', () => {
|
|
|
51
51
|
|
|
52
52
|
describe('GIVEN: Params: wide', () => {
|
|
53
53
|
describe('WHEN: wide is set to true', () => {
|
|
54
|
-
|
|
54
|
+
test('THEN: has container--wide class', () => {
|
|
55
55
|
const $ = cheerio.load(
|
|
56
56
|
renderComponent('browser-banner', {
|
|
57
57
|
...{},
|
|
@@ -64,7 +64,7 @@ describe('FOR: Macro: Browser-banner', () => {
|
|
|
64
64
|
});
|
|
65
65
|
|
|
66
66
|
describe('WHEN: wide is not set', () => {
|
|
67
|
-
|
|
67
|
+
test('THEN: does not have container--wide class', () => {
|
|
68
68
|
const $ = cheerio.load(
|
|
69
69
|
renderComponent('browser-banner', {
|
|
70
70
|
...{},
|
|
@@ -78,7 +78,7 @@ describe('FOR: Macro: Browser-banner', () => {
|
|
|
78
78
|
|
|
79
79
|
describe('GIVEN: Params: fullWidth', () => {
|
|
80
80
|
describe('WHEN: fullWidth is set to true', () => {
|
|
81
|
-
|
|
81
|
+
test('THEN: has container--full-width class', () => {
|
|
82
82
|
const $ = cheerio.load(
|
|
83
83
|
renderComponent('browser-banner', {
|
|
84
84
|
...{},
|
|
@@ -91,7 +91,7 @@ describe('FOR: Macro: Browser-banner', () => {
|
|
|
91
91
|
});
|
|
92
92
|
|
|
93
93
|
describe('WHEN: fullWidth is not set', () => {
|
|
94
|
-
|
|
94
|
+
test('THEN: does not have container--full-width class', () => {
|
|
95
95
|
const $ = cheerio.load(
|
|
96
96
|
renderComponent('browser-banner', {
|
|
97
97
|
...{},
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
{# Default icon position before label #}
|
|
12
12
|
{% set iconPosition = "before" %}
|
|
13
13
|
{% endif %}
|
|
14
|
-
{% elif params.iconType is not defined and params.noIcon
|
|
14
|
+
{% elif params.iconType is not defined and params.noIcon != true %}
|
|
15
15
|
{% if params.url and params.newWindow %}
|
|
16
16
|
{# CTA link opening in new tab #}
|
|
17
17
|
{% set iconType = "external-link" %}
|