Skip to content

Commit 64ac0df

Browse files
authored
Merge branch 'main' into CSS-Cutoff
2 parents 202d403 + a646ae8 commit 64ac0df

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

.changeset/happy-cycles-check.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@spectrum-web-components/overlay': major
3+
---
4+
5+
**Fixed** : Overlays (like pickers and action menus) were incorrectly closing when scrolling occurred within components. The fix ensures the `handleScroll` method in `OverlayStack` only responds to document/body scrolling events and ignores component-level scrolling events, which was the original intention.

packages/overlay/src/OverlayStack.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ class OverlayStack {
4040
}
4141

4242
private handleScroll = (event: Event): void => {
43+
// Only handle document/body level scrolls
44+
// Skip any component scrolls
45+
if (
46+
event.target !== document &&
47+
event.target !== document.documentElement &&
48+
event.target !== document.body
49+
) {
50+
return;
51+
}
4352
// Update positions of all open overlays
4453
this.stack.forEach((overlay) => {
4554
if (overlay.open) {

packages/picker/test/index.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable import/no-extraneous-dependencies */
12
/*
23
Copyright 2020 Adobe. All rights reserved.
34
This file is licensed to you under the Apache License, Version 2.0 (the "License");
@@ -12,6 +13,7 @@ governing permissions and limitations under the License.
1213

1314
import type { Picker } from '@spectrum-web-components/picker';
1415

16+
// eslint-disable-next-line import/no-extraneous-dependencies
1517
import {
1618
aTimeout,
1719
elementUpdated,
@@ -1513,6 +1515,76 @@ export function runPickerTests(): void {
15131515
'Waiting for picker to remain open after scroll'
15141516
);
15151517

1518+
expect(picker.open).to.be.true;
1519+
});
1520+
it('ignores component scrolling but handles document scrolling', async () => {
1521+
const scrollSpy = spy(document, 'dispatchEvent');
1522+
1523+
const el = await fixture(html`
1524+
<div style="height: 200vh; padding: 50vh 0;">
1525+
<div
1526+
id="scrollable-container"
1527+
style="height: 100px; overflow-y: auto;"
1528+
>
1529+
<div style="height: 200px;">Scrollable content</div>
1530+
</div>
1531+
<sp-picker label="Select an option" placement="right">
1532+
<sp-menu-item value="option-1">Option 1</sp-menu-item>
1533+
<sp-menu-item value="option-2">Option 2</sp-menu-item>
1534+
<sp-menu-item value="option-3">Option 3</sp-menu-item>
1535+
</sp-picker>
1536+
</div>
1537+
`);
1538+
1539+
const picker = el.querySelector('sp-picker') as Picker;
1540+
const scrollableContainer = el.querySelector(
1541+
'#scrollable-container'
1542+
) as HTMLElement;
1543+
1544+
await elementUpdated(picker);
1545+
1546+
const opened = oneEvent(picker, 'sp-opened');
1547+
picker.click();
1548+
await opened;
1549+
1550+
expect(picker.open).to.be.true;
1551+
1552+
scrollSpy.resetHistory();
1553+
1554+
scrollableContainer.scrollTop = 50;
1555+
1556+
await aTimeout(50);
1557+
1558+
const componentScrollUpdateCount = scrollSpy
1559+
.getCalls()
1560+
.filter(
1561+
(call) =>
1562+
call.args[0] instanceof CustomEvent &&
1563+
call.args[0].type === 'sp-update-overlays'
1564+
).length;
1565+
1566+
scrollSpy.resetHistory();
1567+
1568+
if (document.scrollingElement) {
1569+
document.scrollingElement.scrollTop = 100;
1570+
}
1571+
1572+
await aTimeout(50);
1573+
1574+
const documentScrollUpdateCount = scrollSpy
1575+
.getCalls()
1576+
.filter(
1577+
(call) =>
1578+
call.args[0] instanceof CustomEvent &&
1579+
call.args[0].type === 'sp-update-overlays'
1580+
).length;
1581+
1582+
scrollSpy.restore();
1583+
1584+
expect(componentScrollUpdateCount).to.equal(0);
1585+
1586+
expect(documentScrollUpdateCount).to.be.greaterThan(0);
1587+
15161588
expect(picker.open).to.be.true;
15171589
});
15181590
});

0 commit comments

Comments
 (0)