File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
import ReactDOM from 'react-dom' ;
3
3
4
+ export function isDOM ( node : any ) {
5
+ // https://developer.mozilla.org/en-US/docs/Web/API/Element
6
+ // Since XULElement is also subclass of Element, we only need HTMLElement and SVGElement
7
+ return node instanceof HTMLElement || node instanceof SVGElement ;
8
+ }
9
+
4
10
/**
5
11
* Return if a node is a DOM node. Else will return by `findDOMNode`
6
12
*/
7
13
export default function findDOMNode < T = Element | Text > (
8
- node : React . ReactInstance | HTMLElement ,
14
+ node : React . ReactInstance | HTMLElement | SVGElement ,
9
15
) : T {
10
- if ( node instanceof HTMLElement ) {
16
+ if ( isDOM ( node ) ) {
11
17
return node as unknown as T ;
12
18
}
13
19
Original file line number Diff line number Diff line change 1
- import * as React from 'react' ;
2
1
import { render } from '@testing-library/react' ;
2
+ import * as React from 'react' ;
3
3
import findDOMNode from '../src/Dom/findDOMNode' ;
4
4
5
5
describe ( 'findDOMNode' , ( ) => {
@@ -55,4 +55,9 @@ describe('findDOMNode', () => {
55
55
expect ( errSpy ) . toHaveBeenCalled ( ) ;
56
56
errSpy . mockRestore ( ) ;
57
57
} ) ;
58
+
59
+ it ( 'support svg' , ( ) => {
60
+ const svg = document . createElementNS ( 'http://www.w3.org/2000/svg' , 'svg' ) ;
61
+ expect ( findDOMNode ( svg ) ) . toBe ( svg ) ;
62
+ } ) ;
58
63
} ) ;
You can’t perform that action at this time.
0 commit comments