Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/2736 error container in pattern marked as hidden but has a focusable element #2801

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
29d9d4d
remove aria-hidden class
precious-onyenaucheya-ons Sep 4, 2023
39c346d
remove div when there are no results or too many results
precious-onyenaucheya-ons Sep 8, 2023
9c30fa6
remove aria-hidden from warning element
precious-onyenaucheya-ons Sep 11, 2023
ef00170
remove aria-hidden from warning element
precious-onyenaucheya-ons Sep 11, 2023
caa0f36
fix screen reader repitition issue
precious-onyenaucheya-ons Sep 15, 2023
77a7d22
Merge branch 'main' into fix/2736-error-container-in-pattern-marked-a…
precious-onyenaucheya-ons Sep 15, 2023
653cac7
fix failing visual test
precious-onyenaucheya-ons Sep 15, 2023
45d019b
remove list and results element whenever there is an error
precious-onyenaucheya-ons Sep 15, 2023
8765d66
update test
precious-onyenaucheya-ons Sep 15, 2023
ccac132
update test
precious-onyenaucheya-ons Sep 18, 2023
6dbcdfa
Merge branch 'main' into fix/2736-error-container-in-pattern-marked-a…
precious-onyenaucheya-ons Sep 18, 2023
b93b671
Update src/components/autosuggest/autosuggest.ui.js
precious-onyenaucheya-ons Sep 19, 2023
1cfb9de
Update src/components/autosuggest/autosuggest.spec.js
precious-onyenaucheya-ons Sep 19, 2023
2fc7a1f
revert changes
precious-onyenaucheya-ons Sep 19, 2023
1f4db2c
revert changes
precious-onyenaucheya-ons Sep 20, 2023
b2505a1
Merge branch 'main' into fix/2736-error-container-in-pattern-marked-a…
precious-onyenaucheya-ons Sep 20, 2023
c5accaa
Merge branch 'main' into fix/2736-error-container-in-pattern-marked-a…
precious-onyenaucheya-ons Sep 25, 2023
e5250e1
Merge branch 'main' into fix/2736-error-container-in-pattern-marked-a…
precious-onyenaucheya-ons Sep 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
precious-onyenaucheya-ons marked this conversation as resolved.
Show resolved Hide resolved

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`);
precious-onyenaucheya-ons marked this conversation as resolved.
Show resolved Hide resolved
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