Skip to content

Commit 9984dfc

Browse files
committed
Update search.js
1 parent 0b8e3c2 commit 9984dfc

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

docs/src/assets/js/search.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,17 @@ document.addEventListener('keydown', function (e) {
214214

215215
const searchResults = Array.from(document.querySelectorAll('.search-results__item'));
216216

217-
if (e.key === 'Escape') {
217+
if (e.key === "Escape") {
218218
e.preventDefault();
219-
searchResults.length ? clearSearchResults(true) : clearNoResults();
220-
searchInput.focus();
219+
if (searchResults.length) {
220+
clearSearchResults(true);
221+
searchInput.focus();
222+
} else if (
223+
document.activeElement === searchInput
224+
) {
225+
clearNoResults();
226+
searchInput.blur();
227+
}
221228
}
222229

223230
if ((e.metaKey || e.ctrlKey) && e.key === 'k') {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy