-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(shadow-dom):
isInDOM
to traverse up the shadow root host
- Loading branch information
1 parent
158c690
commit 485a736
Showing
4 changed files
with
153 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { getConfig } from './config'; | ||
import { isShadowRoot } from './dom-node-safe-guards'; | ||
|
||
/** | ||
* `Element.closest` which traverses tree up when `ShadowRoot` is encountered | ||
*/ | ||
export function closest( | ||
element: Element, | ||
...args: Parameters<Element['closest']> | ||
): ReturnType<Element['closest']> { | ||
const result = element.closest(...args); | ||
|
||
if (result || !getConfig().includeShadowDom) { | ||
return result; | ||
} | ||
|
||
const rootNode = element.getRootNode(); | ||
|
||
if (isShadowRoot(rootNode)) { | ||
return closest(rootNode.host, ...args); | ||
} | ||
|
||
return null; | ||
} |
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