@ons/design-system 65.2.4 → 65.2.5
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.
|
@@ -597,12 +597,20 @@ describe('script: autosuggest', () => {
|
|
|
597
597
|
});
|
|
598
598
|
|
|
599
599
|
it('shows the API error message', async () => {
|
|
600
|
-
const
|
|
601
|
-
expect(
|
|
600
|
+
const resultsItemCount = await page.$$eval('.ons-js-autosuggest-results > *', (nodes) => nodes.length);
|
|
601
|
+
expect(resultsItemCount).toBe(1);
|
|
602
602
|
const warningText = await page.$eval('.ons-autosuggest__warning', (node) => node.textContent);
|
|
603
603
|
expect(warningText.trim()).toBe('!Sorry, there is a problem.');
|
|
604
604
|
});
|
|
605
605
|
|
|
606
|
+
it('the list and results element should be removed from the page', async () => {
|
|
607
|
+
const hasListBox = await page.$eval('.ons-autosuggest', (node) => node.classList.contains('.ons-js-autosuggest-listbox'));
|
|
608
|
+
const hasResultsTitle = await page.$eval('.ons-autosuggest', (node) => node.classList.contains('.ons-autosuggest__results-title'));
|
|
609
|
+
|
|
610
|
+
expect(hasListBox).toBe(false);
|
|
611
|
+
expect(hasResultsTitle).toBe(false);
|
|
612
|
+
});
|
|
613
|
+
|
|
606
614
|
it('the input should be disabled', async () => {
|
|
607
615
|
const hasDisabledAttribute = await page.$eval('.ons-js-autosuggest-input', (node) => node.hasAttribute('disabled'));
|
|
608
616
|
expect(hasDisabledAttribute).toBe(true);
|
|
@@ -43,6 +43,7 @@ export default class AutosuggestUI {
|
|
|
43
43
|
this.input = context.querySelector(`.${baseClass}-input`);
|
|
44
44
|
this.resultsContainer = context.querySelector(`.${baseClass}-results`);
|
|
45
45
|
this.listbox = this.resultsContainer.querySelector(`.${baseClass}-listbox`);
|
|
46
|
+
this.resultsTitleContainer = this.resultsContainer.querySelector(`.ons-autosuggest__results-title`);
|
|
46
47
|
this.instructions = context.querySelector(`.${baseClass}-instructions`);
|
|
47
48
|
this.ariaStatus = context.querySelector(`.${baseClass}-aria-status`);
|
|
48
49
|
this.form = context.closest('form');
|
|
@@ -376,7 +377,10 @@ export default class AutosuggestUI {
|
|
|
376
377
|
|
|
377
378
|
if (this.resultLimit === 100 && this.foundResults > this.resultLimit) {
|
|
378
379
|
let message = this.tooManyResults.replace('{n}', this.foundResults);
|
|
379
|
-
this.
|
|
380
|
+
this.resultsContainer.insertBefore(this.createWarningElement(message), this.resultsContainer.firstChild);
|
|
381
|
+
this.ariaStatus.setAttribute('aria-hidden', 'true');
|
|
382
|
+
this.listbox.remove();
|
|
383
|
+
this.resultsTitleContainer.remove();
|
|
380
384
|
}
|
|
381
385
|
|
|
382
386
|
this.setHighlightedResult(null);
|
|
@@ -414,9 +418,11 @@ export default class AutosuggestUI {
|
|
|
414
418
|
this.input.value = '';
|
|
415
419
|
this.label.classList.add('ons-u-lighter');
|
|
416
420
|
|
|
417
|
-
this.
|
|
418
|
-
this.
|
|
421
|
+
this.resultsContainer.insertBefore(this.createWarningElement(message), this.resultsContainer.firstChild);
|
|
422
|
+
this.ariaStatus.setAttribute('aria-hidden', 'true');
|
|
419
423
|
this.setAriaStatus(ariaMessage);
|
|
424
|
+
this.listbox.remove();
|
|
425
|
+
this.resultsTitleContainer.remove();
|
|
420
426
|
} else {
|
|
421
427
|
message = this.noResults;
|
|
422
428
|
this.listbox.innerHTML = `<li class="${classAutosuggestOption} ${classAutosuggestOptionNoResults}">${message}</li>`;
|
|
@@ -497,13 +503,12 @@ export default class AutosuggestUI {
|
|
|
497
503
|
}
|
|
498
504
|
|
|
499
505
|
createWarningElement(content) {
|
|
500
|
-
const
|
|
506
|
+
const warningContainer = document.createElement('div');
|
|
501
507
|
const warningElement = document.createElement('div');
|
|
502
508
|
const warningSpanElement = document.createElement('span');
|
|
503
509
|
const warningBodyElement = document.createElement('div');
|
|
504
510
|
|
|
505
|
-
|
|
506
|
-
warningListElement.className = 'ons-autosuggest__warning';
|
|
511
|
+
warningContainer.className = 'ons-autosuggest__warning';
|
|
507
512
|
warningElement.className = 'ons-panel ons-panel--warn ons-autosuggest__panel';
|
|
508
513
|
|
|
509
514
|
warningSpanElement.className = 'ons-panel__icon';
|
|
@@ -515,9 +520,9 @@ export default class AutosuggestUI {
|
|
|
515
520
|
|
|
516
521
|
warningElement.appendChild(warningSpanElement);
|
|
517
522
|
warningElement.appendChild(warningBodyElement);
|
|
518
|
-
|
|
523
|
+
warningContainer.appendChild(warningElement);
|
|
519
524
|
|
|
520
|
-
return
|
|
525
|
+
return warningContainer;
|
|
521
526
|
}
|
|
522
527
|
|
|
523
528
|
storeExistingSelections(value) {
|