From fa3ba8c92d1fc65e682a130990dc0d2e09434749 Mon Sep 17 00:00:00 2001 From: Adrian Nita Date: Wed, 6 Jan 2021 17:44:49 +0200 Subject: [PATCH] Fix detection of nearest dialog for shadow DOM usage (#189) --- dist/dialog-polyfill.esm.js | 8 +++++++- dist/dialog-polyfill.js | 8 +++++++- index.js | 8 +++++++- package-lock.json | 2 +- package.json | 2 +- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/dist/dialog-polyfill.esm.js b/dist/dialog-polyfill.esm.js index 471f55e..073d953 100644 --- a/dist/dialog-polyfill.esm.js +++ b/dist/dialog-polyfill.esm.js @@ -64,7 +64,13 @@ function findNearestDialog(el) { if (el.localName === 'dialog') { return /** @type {HTMLDialogElement} */ (el); } - el = el.parentElement; + if (el.parentElement) { + el = el.parentElement; + } else if (el.parentNode) { + el = el.parentNode.host; + } else { + el = null; + } } return null; } diff --git a/dist/dialog-polyfill.js b/dist/dialog-polyfill.js index bd60a70..8dfd245 100644 --- a/dist/dialog-polyfill.js +++ b/dist/dialog-polyfill.js @@ -70,7 +70,13 @@ if (el.localName === 'dialog') { return /** @type {HTMLDialogElement} */ (el); } - el = el.parentElement; + if (el.parentElement) { + el = el.parentElement; + } else if (el.parentNode) { + el = el.parentNode.host; + } else { + el = null; + } } return null; } diff --git a/index.js b/index.js index 3643014..ecddcdd 100644 --- a/index.js +++ b/index.js @@ -65,7 +65,13 @@ function findNearestDialog(el) { if (el.localName === 'dialog') { return /** @type {HTMLDialogElement} */ (el); } - el = el.parentElement; + if (el.parentElement) { + el = el.parentElement; + } else if (el.parentNode) { + el = el.parentNode.host; + } else { + el = null; + } } return null; } diff --git a/package-lock.json b/package-lock.json index fbe505c..e9c7d2b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "dialog-polyfill", - "version": "0.5.2", + "version": "0.5.5", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 4ecce16..6ce9315 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dialog-polyfill", - "version": "0.5.4", + "version": "0.5.5", "description": "Polyfill for the dialog element", "main": "dist/dialog-polyfill.js", "module": "dist/dialog-polyfill.esm.js",