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 11import React from 'react' ;
22import ReactDOM from 'react-dom' ;
33
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+
410/**
511 * Return if a node is a DOM node. Else will return by `findDOMNode`
612 */
713export default function findDOMNode < T = Element | Text > (
8- node : React . ReactInstance | HTMLElement ,
14+ node : React . ReactInstance | HTMLElement | SVGElement ,
915) : T {
10- if ( node instanceof HTMLElement ) {
16+ if ( isDOM ( node ) ) {
1117 return node as unknown as T ;
1218 }
1319
Original file line number Diff line number Diff line change 1- import * as React from 'react' ;
21import { render } from '@testing-library/react' ;
2+ import * as React from 'react' ;
33import findDOMNode from '../src/Dom/findDOMNode' ;
44
55describe ( 'findDOMNode' , ( ) => {
@@ -55,4 +55,9 @@ describe('findDOMNode', () => {
5555 expect ( errSpy ) . toHaveBeenCalled ( ) ;
5656 errSpy . mockRestore ( ) ;
5757 } ) ;
58+
59+ it ( 'support svg' , ( ) => {
60+ const svg = document . createElementNS ( 'http://www.w3.org/2000/svg' , 'svg' ) ;
61+ expect ( findDOMNode ( svg ) ) . toBe ( svg ) ;
62+ } ) ;
5863} ) ;
You can’t perform that action at this time.
0 commit comments