Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/LumexUI/wwwroot/js/components/popover.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -1619,17 +1619,19 @@ function waitForElement(selector) {
});
}

function portal(element, selector = undefined) {
function portal(element, destination = undefined) {
if (!(element instanceof HTMLElement)) {
throw new Error('The provided element is not a valid HTMLElement.');
}

let destination = selector
? document.querySelector(selector)
: document.body;
if (destination instanceof HTMLElement) ; else if (typeof destination === 'string') {
destination = document.querySelector(destination);
} else {
destination = document.body;
}

if (!destination) {
throw new Error(`No portal container with the given selector '${selector}' was found!`);
throw new Error('No portal destination was found.');
}

if (element.parentElement !== destination) {
Expand All @@ -1652,10 +1654,12 @@ async function initialize(id, options) {
const arrowElement = popover.querySelector('[data-slot=arrow]');
const ref = target.children.length === 1 ? target.firstElementChild : target;

portal(popover);
const closestDialog = popover.closest('dialog');

portal(popover, closestDialog);

if (overlay) {
portal(overlay);
portal(overlay, closestDialog);
}

const {
Expand Down
6 changes: 4 additions & 2 deletions src/LumexUI/wwwroot/js/components/popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ async function initialize(id, options) {
const arrowElement = popover.querySelector('[data-slot=arrow]');
const ref = target.children.length === 1 ? target.firstElementChild : target;

portal(popover);
const closestDialog = popover.closest('dialog');

portal(popover, closestDialog);

if (overlay) {
portal(overlay);
portal(overlay, closestDialog);
}

const {
Expand Down
14 changes: 9 additions & 5 deletions src/LumexUI/wwwroot/js/utils/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,21 @@ export function waitForElement(selector) {
});
}

export function portal(element, selector = undefined) {
export function portal(element, destination = undefined) {
if (!(element instanceof HTMLElement)) {
throw new Error('The provided element is not a valid HTMLElement.');
}

let destination = selector
? document.querySelector(selector)
: document.body;
if (destination instanceof HTMLElement) {
// use it directly
} else if (typeof destination === 'string') {
destination = document.querySelector(destination);
} else {
destination = document.body;
}

if (!destination) {
throw new Error(`No portal container with the given selector '${selector}' was found!`);
throw new Error('No portal destination was found.');
}

if (element.parentElement !== destination) {
Expand Down
Loading