UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

24 lines 818 B
import { warn } from "../helpers.js"; export const getClosestParent = (selector, element) => { try { const tagName = /[A-Z]/.test(selector) ? selector : null; const className = tagName ? null : selector.replace(/^\./, ''); const contains = element => { if (!element) { return null; } if (tagName) { return (element === null || element === void 0 ? void 0 : element.tagName) === tagName; } return element === null || element === void 0 ? void 0 : element.classList.contains(className); }; while (element && !contains(element)) { var _element; element = (_element = element) === null || _element === void 0 ? void 0 : _element.parentElement; } } catch (e) { warn(e); } return element; }; //# sourceMappingURL=getClosest.js.map