Skip to content

Commit

Permalink
Merge branch 'main' into dependencies/9/remove-unused-dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
rmccar authored Sep 26, 2023
2 parents 89f40d4 + b9c7d1e commit 3af674f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 10 additions & 2 deletions src/components/autosuggest/autosuggest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,12 +597,20 @@ describe('script: autosuggest', () => {
});

it('shows the API error message', async () => {
const listItemCount = await page.$$eval('.ons-js-autosuggest-listbox > *', (nodes) => nodes.length);
expect(listItemCount).toBe(1);
const resultsItemCount = await page.$$eval('.ons-js-autosuggest-results > *', (nodes) => nodes.length);
expect(resultsItemCount).toBe(1);
const warningText = await page.$eval('.ons-autosuggest__warning', (node) => node.textContent);
expect(warningText.trim()).toBe('!Sorry, there is a problem.');
});

it('the list and results element should be removed from the page', async () => {
const hasListBox = await page.$eval('.ons-autosuggest', (node) => node.classList.contains('.ons-js-autosuggest-listbox'));
const hasResultsTitle = await page.$eval('.ons-autosuggest', (node) => node.classList.contains('.ons-autosuggest__results-title'));

expect(hasListBox).toBe(false);
expect(hasResultsTitle).toBe(false);
});

it('the input should be disabled', async () => {
const hasDisabledAttribute = await page.$eval('.ons-js-autosuggest-input', (node) => node.hasAttribute('disabled'));
expect(hasDisabledAttribute).toBe(true);
Expand Down
21 changes: 13 additions & 8 deletions src/components/autosuggest/autosuggest.ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default class AutosuggestUI {
this.input = context.querySelector(`.${baseClass}-input`);
this.resultsContainer = context.querySelector(`.${baseClass}-results`);
this.listbox = this.resultsContainer.querySelector(`.${baseClass}-listbox`);
this.resultsTitleContainer = this.resultsContainer.querySelector(`.ons-autosuggest__results-title`);
this.instructions = context.querySelector(`.${baseClass}-instructions`);
this.ariaStatus = context.querySelector(`.${baseClass}-aria-status`);
this.form = context.closest('form');
Expand Down Expand Up @@ -376,7 +377,10 @@ export default class AutosuggestUI {

if (this.resultLimit === 100 && this.foundResults > this.resultLimit) {
let message = this.tooManyResults.replace('{n}', this.foundResults);
this.listbox.insertBefore(this.createWarningElement(message), this.listbox.firstChild);
this.resultsContainer.insertBefore(this.createWarningElement(message), this.resultsContainer.firstChild);
this.ariaStatus.setAttribute('aria-hidden', 'true');
this.listbox.remove();
this.resultsTitleContainer.remove();
}

this.setHighlightedResult(null);
Expand Down Expand Up @@ -414,9 +418,11 @@ export default class AutosuggestUI {
this.input.value = '';
this.label.classList.add('ons-u-lighter');

this.listbox.innerHTML = '';
this.listbox.insertBefore(this.createWarningElement(message), this.listbox.firstChild);
this.resultsContainer.insertBefore(this.createWarningElement(message), this.resultsContainer.firstChild);
this.ariaStatus.setAttribute('aria-hidden', 'true');
this.setAriaStatus(ariaMessage);
this.listbox.remove();
this.resultsTitleContainer.remove();
} else {
message = this.noResults;
this.listbox.innerHTML = `<li class="${classAutosuggestOption} ${classAutosuggestOptionNoResults}">${message}</li>`;
Expand Down Expand Up @@ -497,13 +503,12 @@ export default class AutosuggestUI {
}

createWarningElement(content) {
const warningListElement = document.createElement('li');
const warningContainer = document.createElement('div');
const warningElement = document.createElement('div');
const warningSpanElement = document.createElement('span');
const warningBodyElement = document.createElement('div');

warningListElement.setAttribute('aria-hidden', 'true');
warningListElement.className = 'ons-autosuggest__warning';
warningContainer.className = 'ons-autosuggest__warning';
warningElement.className = 'ons-panel ons-panel--warn ons-autosuggest__panel';

warningSpanElement.className = 'ons-panel__icon';
Expand All @@ -515,9 +520,9 @@ export default class AutosuggestUI {

warningElement.appendChild(warningSpanElement);
warningElement.appendChild(warningBodyElement);
warningListElement.appendChild(warningElement);
warningContainer.appendChild(warningElement);

return warningListElement;
return warningContainer;
}

storeExistingSelections(value) {
Expand Down

0 comments on commit 3af674f

Please sign in to comment.