Skip to content
Snippets Groups Projects
Unverified Commit 5c01c200 authored by Lauri Timmanee's avatar Lauri Timmanee
Browse files

Issue #3226785 by mherchel, Gauravmahlawat, thejimbirch, andy-blum, schillerm:...

Issue #3226785 by mherchel, Gauravmahlawat, thejimbirch, andy-blum, schillerm: Olivero: Wide search form should close on blur
parent 8c2a1247
No related branches found
No related tags found
13 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!1896Issue #2940605: Can only intentionally re-render an entity with references 20 times,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!872Draft: Issue #3221319: Race condition when creating menu links and editing content deletes menu links,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!512Issue #3207771: Menu UI node type form documentation points to non-existent function,!485Sets the autocomplete attribute for username/password input field on login form.,!449Issue #2784233: Allow multiple vocabularies in the taxonomy filter,!231Issue #2671162: summary text wysiwyg patch working fine on 9.2.0-dev,!43Resolve #3173180: Add UI for 'loading' html attribute to images,!30Issue #3182188: Updates composer usage to point at ./vendor/bin/composer
...@@ -3,6 +3,7 @@ const headerNavSelector = '#header-nav'; ...@@ -3,6 +3,7 @@ const headerNavSelector = '#header-nav';
const searchButtonSelector = 'button.block-search-wide__button'; const searchButtonSelector = 'button.block-search-wide__button';
const searchFormSelector = '.search-form.search-block-form'; const searchFormSelector = '.search-form.search-block-form';
const searchWideSelector = '.block-search-wide__wrapper'; const searchWideSelector = '.block-search-wide__wrapper';
const searchWideInputSelector = '#edit-keys--2';
const searchNarrowSelector = '.block-search-narrow'; const searchNarrowSelector = '.block-search-narrow';
module.exports = { module.exports = {
...@@ -32,24 +33,57 @@ module.exports = { ...@@ -32,24 +33,57 @@ module.exports = {
.waitForElementVisible(searchButtonSelector) .waitForElementVisible(searchButtonSelector)
.assert.attributeEquals(searchButtonSelector, 'aria-expanded', 'false') .assert.attributeEquals(searchButtonSelector, 'aria-expanded', 'false')
.click(searchButtonSelector) .click(searchButtonSelector)
.waitForElementVisible(`${searchWideSelector}`) .waitForElementVisible(searchWideInputSelector)
.waitForElementVisible(`${searchWideSelector} ${searchFormSelector}`)
.assert.attributeEquals(searchButtonSelector, 'aria-expanded', 'true') .assert.attributeEquals(searchButtonSelector, 'aria-expanded', 'true')
.assert.attributeContains( .assert.attributeContains(
`${searchWideSelector} ${searchFormSelector} input[name=keys]`, searchWideInputSelector,
'placeholder', 'placeholder',
'Search by keyword or phrase.', 'Search by keyword or phrase.',
) )
.assert.attributeContains( .assert.attributeContains(
`${searchWideSelector} ${searchFormSelector} input[name=keys]`, searchWideInputSelector,
'title', 'title',
'Enter the terms you wish to search for.', 'Enter the terms you wish to search for.',
) )
.assert.elementPresent('button.search-form__submit') .assert.elementPresent('button.search-form__submit')
// Assert wide search form closes when element moves to body.
.click('body') .click('body')
.waitForElementNotVisible(`${searchWideSelector}`) .waitForElementNotVisible(searchWideSelector)
.assert.attributeEquals(searchButtonSelector, 'aria-expanded', 'false'); .assert.attributeEquals(searchButtonSelector, 'aria-expanded', 'false');
}, },
'Test focus management': (browser) => {
browser
.drupalRelativeURL('/')
.waitForElementVisible(searchButtonSelector)
.click(searchButtonSelector)
.waitForElementVisible(searchWideInputSelector)
.pause(400) // Wait for transitionend event to fire.
// Assert that focus is moved to wide search text input.
.execute(
// eslint-disable-next-line func-names, prefer-arrow-callback, no-shadow
function (searchWideInputSelector) {
return document.activeElement.matches(searchWideInputSelector);
},
[searchWideInputSelector],
(result) => {
browser.assert.ok(
result.value,
'Assert that focus moves to wide search form on open.',
);
},
)
// Assert that search form is still visible when focus is on disclosure button.
.keys(browser.Keys.SHIFT)
.keys(browser.Keys.TAB)
.pause(50)
.isVisible(searchWideSelector)
// Assert that search form is NOT visible when focus moves back to menu item.
.keys(browser.Keys.TAB)
.pause(50)
.waitForElementNotVisible(searchWideSelector)
// Release all keys.
.keys(browser.Keys.NULL);
},
'search narrow form is accessible': (browser) => { 'search narrow form is accessible': (browser) => {
browser browser
.resizeWindow(1000, 800) .resizeWindow(1000, 800)
......
...@@ -28,7 +28,8 @@ ...@@ -28,7 +28,8 @@
function handleFocus() { function handleFocus() {
if (searchIsVisible()) { if (searchIsVisible()) {
searchWideWrapper.querySelector('input[type="search"]').focus(); searchWideWrapper.querySelector('input[type="search"]').focus();
} else { } else if (searchWideWrapper.contains(document.activeElement)) {
// Return focus to button only if focus was inside of the search wrapper.
searchWideButton.focus(); searchWideButton.focus();
} }
} }
...@@ -61,21 +62,8 @@ ...@@ -61,21 +62,8 @@
} }
}); });
document.addEventListener('click', (e) => { searchWideButton.addEventListener('click', () => {
if ( toggleSearchVisibility(!searchIsVisible());
e.target.matches(
'[data-drupal-selector="block-search-wide-button"], [data-drupal-selector="block-search-wide-button"] *',
)
) {
toggleSearchVisibility(!searchIsVisible());
} else if (
searchIsVisible() &&
!e.target.matches(
'[data-drupal-selector="block-search-wide-wrapper"], [data-drupal-selector="block-search-wide-wrapper"] *',
)
) {
toggleSearchVisibility(false);
}
}); });
/** /**
...@@ -98,4 +86,16 @@ ...@@ -98,4 +86,16 @@
} }
}, },
}; };
/**
* Close the wide search container if focus moves from either the container
* or its toggle button.
*/
document
.querySelector('[data-drupal-selector="search-block-form-2"]')
.addEventListener('focusout', (e) => {
if (!e.currentTarget.contains(e.relatedTarget)) {
toggleSearchVisibility(false);
}
});
})(Drupal); })(Drupal);
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
function handleFocus() { function handleFocus() {
if (searchIsVisible()) { if (searchIsVisible()) {
searchWideWrapper.querySelector('input[type="search"]').focus(); searchWideWrapper.querySelector('input[type="search"]').focus();
} else { } else if (searchWideWrapper.contains(document.activeElement)) {
searchWideButton.focus(); searchWideButton.focus();
} }
} }
...@@ -43,12 +43,8 @@ ...@@ -43,12 +43,8 @@
toggleSearchVisibility(false); toggleSearchVisibility(false);
} }
}); });
document.addEventListener('click', function (e) { searchWideButton.addEventListener('click', function () {
if (e.target.matches('[data-drupal-selector="block-search-wide-button"], [data-drupal-selector="block-search-wide-button"] *')) { toggleSearchVisibility(!searchIsVisible());
toggleSearchVisibility(!searchIsVisible());
} else if (searchIsVisible() && !e.target.matches('[data-drupal-selector="block-search-wide-wrapper"], [data-drupal-selector="block-search-wide-wrapper"] *')) {
toggleSearchVisibility(false);
}
}); });
Drupal.behaviors.searchWide = { Drupal.behaviors.searchWide = {
attach: function attach(context) { attach: function attach(context) {
...@@ -59,4 +55,9 @@ ...@@ -59,4 +55,9 @@
} }
} }
}; };
document.querySelector('[data-drupal-selector="search-block-form-2"]').addEventListener('focusout', function (e) {
if (!e.currentTarget.contains(e.relatedTarget)) {
toggleSearchVisibility(false);
}
});
})(Drupal); })(Drupal);
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment