1+ /* eslint-disable import/no-extraneous-dependencies */
12/*
23Copyright 2020 Adobe. All rights reserved.
34This 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
1314import type { Picker } from '@spectrum-web-components/picker' ;
1415
16+ // eslint-disable-next-line import/no-extraneous-dependencies
1517import {
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