UNPKG

rsuite

Version:

A suite of react components

22 lines (21 loc) 776 B
'use client'; function safeFindDOMNode(componentOrElement) { if (componentOrElement && 'setState' in componentOrElement) { // Access the underlying DOM node through ref if available return componentOrElement?.ref?.current ?? null; } return componentOrElement ?? null; } const getRefTarget = ref => { return ref && ('current' in ref ? ref.current : ref); }; export function getDOMNode(elementOrRef) { // If elementOrRef is an instance of Position, child is returned. [PositionInstance] const element = elementOrRef?.root || elementOrRef?.child || getRefTarget(elementOrRef); // Native HTML elements if (element?.nodeType && typeof element?.nodeName === 'string') { return element; } return safeFindDOMNode(element); } export default getDOMNode;