Skip to content

Commit fdaf550

Browse files
committed
add types for isFocused
1 parent db84fc5 commit fdaf550

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

core/src/utils/input-shims/hacks/common.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,17 @@ export const relocateInput = (
1818
}
1919
};
2020

21-
// TODO(FW-2832): type
2221
export const isFocused = (input: HTMLInputElement | HTMLTextAreaElement): boolean => {
23-
return input === (input as any).getRootNode().activeElement;
22+
/**
23+
* https://developer.mozilla.org/en-US/docs/Web/API/Node/getRootNode
24+
* Calling getRootNode on an element in standard web page will return HTMLDocument.
25+
* Calling getRootNode on an element inside of the Shadow DOM will return the associated ShadowRoot.
26+
* Calling getRootNode on an element that is not attached to a document/shadow tree will return
27+
* the root of the DOM tree it belongs to.
28+
* isFocused is used for the hide-caret utility which only considers input/textarea elements
29+
* that are present in the DOM, so we don't set types for that final case since since it does not apply.
30+
*/
31+
return input === (input.getRootNode() as HTMLDocument | ShadowRoot).activeElement;
2432
};
2533

2634
const addClone = (

0 commit comments

Comments
 (0)