Skip to content

Commit

Permalink
Merge pull request #3864 from 10up/fix/3824
Browse files Browse the repository at this point in the history
Don't open instant results modal if an autosuggest suggestion is selected.
  • Loading branch information
felipeelia authored Mar 18, 2024
2 parents 66ebdd9 + 41d9dcf commit c014edc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions assets/js/autosuggest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ function updateAutosuggestBox(options, input) {
}
});

setInputActiveDescendant('', input);

return true;
}

Expand All @@ -373,6 +375,7 @@ function updateAutosuggestBox(options, input) {
function hideAutosuggestBox() {
const lists = document.querySelectorAll('.autosuggest-list');
const containers = document.querySelectorAll('.ep-autosuggest');
const inputs = document.querySelectorAll('.ep-autosuggest-container [aria-activedescendant]');

// empty all EP results lists
lists.forEach((list) => {
Expand All @@ -387,6 +390,9 @@ function hideAutosuggestBox() {
container.style = 'display: none;';
});

// Remove active descendant attribute from all inputs
inputs.forEach((input) => setInputActiveDescendant('', input));

return true;
}

Expand Down
9 changes: 9 additions & 0 deletions assets/js/instant-results/apps/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ export default () => {

inputRef.current = event.target.s;

/**
* Don't open the modal if an autosuggest suggestion is selected.
*/
const activeDescendant = inputRef.current.getAttribute('aria-activedescendant');

if (activeDescendant) {
return;
}

const { value } = inputRef.current;
const post_type = getPostTypesFromForm(inputRef.current.form);

Expand Down
8 changes: 8 additions & 0 deletions tests/cypress/integration/features/autosuggest.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ describe('Autosuggest Feature', () => {
});

beforeEach(() => {
cy.maybeDisableFeature('instant-results');
cy.deactivatePlugin('custom-headers-for-autosuggest', 'wpCli');
});

Expand Down Expand Up @@ -102,4 +103,11 @@ describe('Autosuggest Feature', () => {
cy.get('.ep-autosuggest li a').first().click();
cy.url().should('include', 'cypress=foobar');
});

it('Can select an Autosuggest suggestion even if Instant Results is active', () => {
cy.maybeEnableFeature('instant-results');
cy.visit('/');
cy.get('.wp-block-search__input').type('blog{downArrow}{enter}');
cy.url().should('include', 'blog');
});
});

0 comments on commit c014edc

Please sign in to comment.