Open History to see the last commit
1const EDITABLE_SELECTOR = [
2 "input",
3 "textarea",
4 "select",
5 '[contenteditable=""]',
6 '[contenteditable="true"]',
7 '[contenteditable="plaintext-only"]',
8 '[role="textbox"]',
9].join(",");
10
11/**
12 * Focus inside an open shadow root counts: a key event's target is retargeted
13 * to the shadow host, so the host's focused descendant is what is typed into.
14 */
15export function isEditableFocused(target: EventTarget | null = document.activeElement): boolean {
16 let element = target instanceof Element ? target : null;
17 while (element?.shadowRoot?.activeElement) element = element.shadowRoot.activeElement;
18 return element !== null && element.closest(EDITABLE_SELECTOR) !== null;
19}