Skip to content

Commit 3e84ecb

Browse files
committed
test: check for scroll parents
1 parent 4d46b8d commit 3e84ecb

File tree

2 files changed

+36
-25
lines changed

2 files changed

+36
-25
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export class UUIPopoverContainerElement extends LitElement {
135135
);
136136

137137
if (this._open) {
138-
this.#getScrollParents();
138+
this.#calculateScrollParents();
139139

140140
this.#startScrollListener();
141141

@@ -344,7 +344,14 @@ export class UUIPopoverContainerElement extends LitElement {
344344
document.removeEventListener('scroll', this.#initUpdate);
345345
}
346346

347-
#getScrollParents(): void {
347+
/**
348+
* @internal
349+
*/
350+
_getScrollParents() {
351+
return this.#scrollParents;
352+
}
353+
354+
#calculateScrollParents(): void {
348355
// Clear previous scroll parents to avoid duplicates
349356
this.#scrollParents = [];
350357

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

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,21 @@ describe('UUIPopoverContainerElement', () => {
3030
it('should properly detect scroll parents in nested shadow DOM containers', async () => {
3131
// Create a test structure with nested shadow DOM and scroll containers
3232
const testContainer = await fixture(html`
33-
<div style="height: 300px; overflow: auto;" id="outer-scroll">
34-
<div style="height: 200px; overflow: auto;" id="inner-scroll">
35-
<div style="height: 100px;"></div>
36-
<uui-button id="trigger-button" popovertarget="test-popover"
37-
>Open</uui-button
38-
>
39-
<div style="height: 400px;"></div>
33+
<main>
34+
<div style="height: 300px; overflow: auto;" id="outer-scroll">
35+
<div style="height: 200px; overflow: auto;" id="inner-scroll">
36+
<div style="height: 100px;"></div>
37+
<uui-button id="trigger-button" popovertarget="test-popover"
38+
>Open</uui-button
39+
>
40+
<div style="height: 400px;"></div>
41+
</div>
42+
<div style="height: 500px;"></div>
4043
</div>
41-
<div style="height: 500px;"></div>
42-
</div>
43-
<uui-popover-container id="test-popover" popover>
44-
Test content
45-
</uui-popover-container>
44+
<uui-popover-container id="test-popover" popover>
45+
Test content
46+
</uui-popover-container>
47+
</main>
4648
`);
4749

4850
const popover = testContainer.querySelector(
@@ -55,7 +57,7 @@ describe('UUIPopoverContainerElement', () => {
5557
await new Promise(resolve => setTimeout(resolve, 100));
5658

5759
// Access the private scroll parents array for testing
58-
const scrollParents = (popover as any)['#scrollParents'];
60+
const scrollParents = popover._getScrollParents();
5961

6062
// Should find both scroll containers
6163
expect(scrollParents.length).to.be.greaterThan(0);
@@ -66,15 +68,17 @@ describe('UUIPopoverContainerElement', () => {
6668

6769
it('should reset scroll parents when called multiple times', async () => {
6870
const testContainer = await fixture(html`
69-
<div style="height: 300px; overflow: auto;" id="scroll-container">
70-
<uui-button id="trigger-button" popovertarget="test-popover"
71-
>Open</uui-button
72-
>
73-
<div style="height: 400px;"></div>
74-
</div>
75-
<uui-popover-container id="test-popover" popover>
76-
Test content
77-
</uui-popover-container>
71+
<main>
72+
<div style="height: 300px; overflow: auto;" id="scroll-container">
73+
<uui-button id="trigger-button" popovertarget="test-popover"
74+
>Open</uui-button
75+
>
76+
<div style="height: 400px;"></div>
77+
</div>
78+
<uui-popover-container id="test-popover" popover>
79+
Test content
80+
</uui-popover-container>
81+
</main>
7882
`);
7983

8084
const popover = testContainer.querySelector(
@@ -91,7 +95,7 @@ describe('UUIPopoverContainerElement', () => {
9195
button?.click();
9296
await new Promise(resolve => setTimeout(resolve, 50));
9397

94-
const scrollParents = (popover as any)['#scrollParents'];
98+
const scrollParents = popover._getScrollParents();
9599

96100
// Should not have duplicate entries
97101
const uniqueParents = [...new Set(scrollParents)];

0 commit comments

Comments
 (0)