u
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user