fix(core): delay blur event for search suggestions

This is a hacky way to fix fix #404 and #410. By introducing a delay to
the function to dismiss the suggestions, users on Safari should be able
to click the link properly.
This commit is contained in:
alistair3149 2022-06-03 22:33:28 -04:00
parent f505f30b89
commit 9d8a631f44

View file

@ -304,21 +304,23 @@ function initTypeahead( searchForm, input ) {
};
const onBlur = function ( event ) {
const clickInside = typeahead.contains( event.relatedTarget );
const focusIn = typeahead.contains( event.relatedTarget );
if ( !clickInside ) {
searchInput.setAttribute( 'aria-activedescendant', '' );
typeahead.classList.remove( expandedClass );
searchInput.removeEventListener( 'keydown', keyboardEvents );
searchInput.removeEventListener( 'blur', onBlur );
if ( !focusIn ) {
// HACK: On Safari, users are unable to click any links because the blur
// event dismiss the links before it is clicked. This should fix it.
setTimeout( () => {
searchInput.setAttribute( 'aria-activedescendant', '' );
typeahead.classList.remove( expandedClass );
searchInput.removeEventListener( 'keydown', keyboardEvents );
searchInput.removeEventListener( 'blur', onBlur );
}, 10 );
}
};
const onFocus = function () {
// Refresh the typeahead since the query will be emptied when blurred
updateTypeahead( messages );
typeahead.classList.add( expandedClass );
searchInput.addEventListener( 'keydown', keyboardEvents );
searchInput.addEventListener( 'blur', onBlur );