1
+ /* eslint-disable import/no-extraneous-dependencies */
1
2
/*
2
3
Copyright 2020 Adobe. All rights reserved.
3
4
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.
12
13
13
14
import type { Picker } from '@spectrum-web-components/picker' ;
14
15
16
+ // eslint-disable-next-line import/no-extraneous-dependencies
15
17
import {
16
18
aTimeout ,
17
19
elementUpdated ,
@@ -1513,6 +1515,76 @@ export function runPickerTests(): void {
1513
1515
'Waiting for picker to remain open after scroll'
1514
1516
) ;
1515
1517
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
+
1516
1588
expect ( picker . open ) . to . be . true ;
1517
1589
} ) ;
1518
1590
} ) ;
0 commit comments