Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,21 @@ export class UUIPopoverContainerElement extends LitElement {
const isEnd = this._actualPlacement.indexOf('-end') !== -1;

const targetRect = this.#targetElement.getBoundingClientRect();

// Clamp left and top within screen bounds
// If the target leaves the screen, the popover follows.
const screenWidth = window.innerWidth;
const screenHeight = window.innerHeight;

if (isBottomPlacement) {
const availableSpaceBelow =
screenHeight - (targetRect.top + targetRect.height) - this.margin;
this.style.maxHeight = `${Math.max(100, availableSpaceBelow * 0.9)}px`;
} else if (isTopPlacement) {
const availableSpaceAbove = targetRect.top - this.margin;
this.style.maxHeight = `${Math.max(100, availableSpaceAbove * 0.9)}px`;
}

const popoverRect = this.getBoundingClientRect();

let top = 0;
Expand Down Expand Up @@ -226,11 +241,6 @@ export class UUIPopoverContainerElement extends LitElement {
}
}

// Clamp left and top within screen bounds
// If the target leaves the screen, the popover follows.
const screenWidth = window.innerWidth;
const screenHeight = window.innerHeight;

const topTargetVsScreenTop = Math.min(
0,
targetRect.top + targetRect.height,
Expand Down Expand Up @@ -334,12 +344,14 @@ export class UUIPopoverContainerElement extends LitElement {
el.addEventListener('scroll', this.#initUpdate, { passive: true });
});
document.addEventListener('scroll', this.#initUpdate, { passive: true });
window.addEventListener('resize', this.#initUpdate, { passive: true });
}
#stopScrollListener() {
this.#scrollParents.forEach(el => {
el.removeEventListener('scroll', this.#initUpdate);
});
document.removeEventListener('scroll', this.#initUpdate);
window.removeEventListener('resize', this.#initUpdate);
}

/**
Expand Down Expand Up @@ -417,7 +429,7 @@ export class UUIPopoverContainerElement extends LitElement {
padding: 0;
background-color: none;
background: none;
overflow: visible;
overflow: auto;
color: var(--uui-color-text);
}
`,
Expand Down
Loading