UNPKG

rsuite

Version:

A suite of react components

27 lines (25 loc) 888 B
'use client'; "use strict"; exports.__esModule = true; exports.default = void 0; exports.getDOMNode = getDOMNode; 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); }; 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); } var _default = exports.default = getDOMNode;