-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: #2702
- Loading branch information
Showing
2 changed files
with
27 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Thx rc-util | ||
* copied from https://github.com/react-component/util/blob/v5.44.3/src/Dom/findDOMNode.ts#L4-L23 | ||
*/ | ||
|
||
export function isDOM(node: any): node is HTMLElement | SVGElement { | ||
// https://developer.mozilla.org/en-US/docs/Web/API/Element | ||
// Since XULElement is also subclass of Element, we only need HTMLElement and SVGElement | ||
return node instanceof HTMLElement || node instanceof SVGElement; | ||
} | ||
|
||
/** | ||
* Retrieves a DOM node via a ref, and does not invoke `findDOMNode`. | ||
*/ | ||
export function getDOM(node: any): HTMLElement | SVGElement | null { | ||
if (node && typeof node === 'object' && isDOM(node.nativeElement)) { | ||
return node.nativeElement; | ||
} | ||
|
||
if (isDOM(node)) { | ||
return node as any; | ||
} | ||
|
||
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