Replaced JS logic with CSS focus-within logic
This commit is contained in:
parent
851ab47f8a
commit
2c1f20969a
2 changed files with 1 additions and 13 deletions
|
@ -15,8 +15,6 @@ class GlobalSearch {
|
||||||
}
|
}
|
||||||
|
|
||||||
setupListeners() {
|
setupListeners() {
|
||||||
this.hideOnOuterEventListener = this.hideOnOuterEventListener.bind(this);
|
|
||||||
|
|
||||||
this.input.addEventListener('input', () => {
|
this.input.addEventListener('input', () => {
|
||||||
const value = this.input.value;
|
const value = this.input.value;
|
||||||
if (value.length > 0) {
|
if (value.length > 0) {
|
||||||
|
@ -45,8 +43,6 @@ class GlobalSearch {
|
||||||
|
|
||||||
showSuggestions() {
|
showSuggestions() {
|
||||||
this.container.classList.add('search-active');
|
this.container.classList.add('search-active');
|
||||||
document.addEventListener('click', this.hideOnOuterEventListener);
|
|
||||||
document.addEventListener('focusin', this.hideOnOuterEventListener);
|
|
||||||
window.requestAnimationFrame(() => {
|
window.requestAnimationFrame(() => {
|
||||||
this.suggestions.classList.add('search-suggestions-animation');
|
this.suggestions.classList.add('search-suggestions-animation');
|
||||||
})
|
})
|
||||||
|
@ -56,15 +52,7 @@ class GlobalSearch {
|
||||||
this.container.classList.remove('search-active');
|
this.container.classList.remove('search-active');
|
||||||
this.suggestions.classList.remove('search-suggestions-animation');
|
this.suggestions.classList.remove('search-suggestions-animation');
|
||||||
this.suggestionResultsWrap.innerHTML = '';
|
this.suggestionResultsWrap.innerHTML = '';
|
||||||
document.removeEventListener('click', this.hideOnOuterEventListener);
|
|
||||||
document.removeEventListener('focusin', this.hideOnOuterEventListener);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hideOnOuterEventListener(event) {
|
|
||||||
if (!this.container.contains(event.target)) {
|
|
||||||
this.hideSuggestions();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default GlobalSearch;
|
export default GlobalSearch;
|
|
@ -164,7 +164,7 @@ header .search-box {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.search-active .global-search-suggestions {
|
.search-active:focus-within .global-search-suggestions {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
header .search-box.search-active input {
|
header .search-box.search-active input {
|
||||||
|
|
Loading…
Reference in a new issue