This commit is contained in:
seb
2026-10-04 02:13:50 +02:00
parent 0d0c5dfdfb
commit f2fce9097b
19 changed files with 3087 additions and 9 deletions

View File

@@ -1,8 +1,16 @@
const FOCUSABLE =
'a, button, input, textarea, select, [role="button"], [role="menuitem"], [tabindex]:not([tabindex="-1"]), [contenteditable="true"]';
/** Keep the search field focused when clicking non-interactive chrome. */
/**
* Keep the search field focused when clicking non-interactive chrome.
*
* Attach to `mouseup`, not `mousedown`: preventing default on mousedown also
* blocks text selection. Instead we let the click/drag happen and restore
* focus afterwards, unless the user just selected some text.
*/
export function preserveSearchFocus(e) {
if (e.target.closest(FOCUSABLE)) return;
e.preventDefault();
const selection = window.getSelection?.();
if (selection && !selection.isCollapsed) return;
document.querySelector('input[type="search"]')?.focus({ preventScroll: true });
}