Skip to content

Commit d7e7fff

Browse files
committed
Search Focus Fixed
1 parent e1d709f commit d7e7fff

1 file changed

Lines changed: 25 additions & 6 deletions

File tree

static/js/search-palette.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,27 @@
258258
}
259259
}
260260

261+
function focusSearchInput() {
262+
if (!input) return;
263+
var opts = { preventScroll: true };
264+
if (document.activeElement && document.activeElement.closest && document.activeElement.closest('[data-search-open]')) {
265+
document.activeElement.blur();
266+
}
267+
input.focus(opts);
268+
requestAnimationFrame(function () {
269+
if (!input) return;
270+
input.focus(opts);
271+
requestAnimationFrame(function () {
272+
if (!input) return;
273+
input.focus(opts);
274+
});
275+
});
276+
setTimeout(function () {
277+
if (!input || !isOpen) return;
278+
input.focus(opts);
279+
}, 220);
280+
}
281+
261282
function isPaletteVisible() {
262283
return !!(palette && palette.classList.contains('is-visible'));
263284
}
@@ -285,18 +306,18 @@
285306

286307
if (isEmbedded) {
287308
if (input) {
288-
input.focus();
309+
focusSearchInput();
289310
runSearch(query || input.value || '');
290311
}
291312
return;
292313
}
293314
if (isOpen && isPaletteVisible()) {
294315
if (input) {
295-
input.focus();
296316
if (query) {
297317
input.value = query;
298318
runSearch(query);
299319
}
320+
focusSearchInput();
300321
}
301322
return;
302323
}
@@ -319,9 +340,7 @@
319340
if (input) {
320341
input.value = query || '';
321342
runSearch(input.value);
322-
requestAnimationFrame(function () {
323-
if (input) input.focus();
324-
});
343+
focusSearchInput();
325344
}
326345
}
327346

@@ -514,7 +533,7 @@
514533
if (input) {
515534
input.value = q;
516535
runSearch(q);
517-
input.focus();
536+
focusSearchInput();
518537
}
519538
}
520539

0 commit comments

Comments
 (0)