-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(picker): fix focus handling of picker in edge
- Loading branch information
1 parent
37b5d66
commit 24bbe71
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Check if an element is a descendant of another, even if it is located within a shadow root | ||
* | ||
* @param {Node} element the element to check | ||
* @param {Node} parent the parent element | ||
* | ||
* @returns {boolean} true if the element is a descendant of the parent element, false otherwise | ||
*/ | ||
export function isDescendant(element: Node, parent: Node) { | ||
if (parent.contains(element)) { | ||
return true; | ||
} | ||
|
||
let currentNode: Node = element; | ||
let i = 0; // Just in case something weird happens, let's not crash the browser… | ||
const DEPTH = 1000; // Max depth to search. | ||
|
||
while ( | ||
i < DEPTH && | ||
currentNode && | ||
currentNode.getRootNode().nodeName === '#document-fragment' | ||
) { | ||
currentNode = (currentNode.getRootNode() as any).host; | ||
if (parent.contains(currentNode)) { | ||
return true; | ||
} | ||
i += 1; | ||
} | ||
return parent.contains(currentNode); | ||
} |