Skip to content

Commit 3ae601b

Browse files
Fix stuck while loop where the checked element never gets updated (#1140)
* Fix stuck while loop where the checked element never got updated * improve story to cover issue --------- Co-authored-by: Niels Lyngsø <[email protected]>
1 parent a2e6078 commit 3ae601b

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

packages/uui-popover-container/lib/uui-popover-container-shadowdomtester.element.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ export class UUIPopoverContainerShadowDomTesterElement extends LitElement {
1010
return html`<div
1111
style="height: 500px; overflow: auto; outline: 1px solid black">
1212
<div
13-
style="width: 300px; height: 300px; outline: 1px solid black; overflow: auto;">
13+
style="position:relative; width: 300px; height: 300px; outline: 1px solid black; overflow: auto;">
1414
<div style="height: 150px"></div>
1515
<uui-button
1616
id="popover-button"
17+
style="position: absolute; top: 50px; left: 50px;"
1718
popovertarget="popover-container"
1819
look="primary"
1920
label="Open popover">
@@ -28,7 +29,8 @@ export class UUIPopoverContainerShadowDomTesterElement extends LitElement {
2829
<div
2930
style="width: 100%; background-color: var(--uui-color-surface); max-width: 200px; box-shadow: var(--uui-shadow-depth-4); padding: var(--uui-size-space-4); border-radius: var(--uui-border-radius); font-size: 0.9rem;">
3031
<h3>Scroll!</h3>
31-
Scrolling in any of the 2 boxes should trigger an update
32+
Scrolling in any of the 2 boxes that are in a shadow-dom inside 2
33+
boxes should trigger an update
3234
</div>
3335
</uui-popover-container>`;
3436
}

packages/uui-popover-container/lib/uui-popover-container.element.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ export class UUIPopoverContainerElement extends LitElement {
359359
style = getComputedStyle(el);
360360

361361
if (excludeStaticParent && style.position === 'static') {
362+
el = this.#getAncestorElement(el);
362363
continue;
363364
}
364365
if (
@@ -370,16 +371,20 @@ export class UUIPopoverContainerElement extends LitElement {
370371
return;
371372
}
372373

373-
if (el.parentElement) {
374-
el = el.parentElement;
375-
} else {
376-
// If we had no parentElement, then check for shadow roots:
377-
el = (el.getRootNode() as any)?.host;
378-
}
374+
el = this.#getAncestorElement(el);
379375
}
380376
this.#scrollParents.push(document.body);
381377
}
382378

379+
#getAncestorElement(el: HTMLElement | null): HTMLElement | null {
380+
if (el?.parentElement) {
381+
return el.parentElement;
382+
} else {
383+
// If we had no parentElement, then check for shadow roots:
384+
return (el?.getRootNode() as any)?.host;
385+
}
386+
}
387+
383388
render() {
384389
return html`<slot></slot>`;
385390
}

packages/uui-popover-container/lib/uui-popover-container.story.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export const InsideShadowDOMScrollContainer: Story = {
230230
render: () => html`
231231
<div style="height: 500px; overflow: auto; outline: 1px solid black">
232232
<div
233-
style="width: 300px; height: 300px; outline: 1px solid black; overflow: auto;">
233+
style="position:static; width: 300px; height: 300px; outline: 1px solid black; overflow: auto;">
234234
<div style="height: 150px"></div>
235235
<uui-popover-container-shadowdomtester></uui-popover-container-shadowdomtester>
236236
<div style="height: 150px"></div>

0 commit comments

Comments
 (0)