From f39b351f10d7700b77ed7fdea9a47c8b88f6163d Mon Sep 17 00:00:00 2001 From: mertsincan Date: Tue, 19 Dec 2023 12:17:30 +0000 Subject: [PATCH] Fixed #3037 - Using primevue inside shadow-dom --- components/lib/utils/DomHandler.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/components/lib/utils/DomHandler.js b/components/lib/utils/DomHandler.js index a061b0a0e..52253b169 100755 --- a/components/lib/utils/DomHandler.js +++ b/components/lib/utils/DomHandler.js @@ -114,7 +114,7 @@ export default { index(element) { if (element) { - let children = element.parentNode.childNodes; + let children = this.getParentNode(element)?.childNodes; let num = 0; for (let i = 0; i < children.length; i++) { @@ -392,8 +392,20 @@ export default { } }, + getParentNode(element) { + let parent = element?.parentNode; + + if (parent && parent.host) { + parent = parent.host; + } + + return parent; + }, + getParents(element, parents = []) { - return element['parentNode'] === null ? parents : this.getParents(element.parentNode, parents.concat([element.parentNode])); + const parent = this.getParentNode(element); + + return parent === null ? parents : this.getParents(parent, parents.concat([parent])); }, getScrollableParents(element) { @@ -649,7 +661,7 @@ export default { }, isExist(element) { - return !!(element !== null && typeof element !== 'undefined' && element.nodeName && element.parentNode); + return !!(element !== null && typeof element !== 'undefined' && element.nodeName && this.getParentNode(element)); }, isClient() {