@@ -61,35 +61,17 @@ export class OverflowController implements ReactiveController {
6161 if ( ! this . #container) {
6262 return ;
6363 }
64- let firstElementInView : HTMLElement | undefined ;
65- let lastElementOutOfView : HTMLElement | undefined ;
66- for ( let i = 0 ; i < this . #items. length && ! firstElementInView ; i ++ ) {
67- if ( isElementInView ( this . #container, this . #items[ i ] as HTMLElement , false ) ) {
68- firstElementInView = this . #items[ i ] ;
69- lastElementOutOfView = this . #items[ i - 1 ] ;
70- }
71- }
72- if ( lastElementOutOfView ) {
73- this . #container. scrollLeft -= lastElementOutOfView . scrollWidth ;
74- }
64+ const leftScroll = this . #container. scrollLeft - this . #container. clientWidth ;
65+ this . #container. scroll ( { left : leftScroll } ) ;
7566 this . #setOverflowState( ) ;
7667 }
7768
7869 scrollRight ( ) {
7970 if ( ! this . #container) {
8071 return ;
8172 }
82- let lastElementInView : HTMLElement | undefined ;
83- let firstElementOutOfView : HTMLElement | undefined ;
84- for ( let i = this . #items. length - 1 ; i >= 0 && ! lastElementInView ; i -- ) {
85- if ( isElementInView ( this . #container, this . #items[ i ] as HTMLElement , false ) ) {
86- lastElementInView = this . #items[ i ] ;
87- firstElementOutOfView = this . #items[ i + 1 ] ;
88- }
89- }
90- if ( firstElementOutOfView ) {
91- this . #container. scrollLeft += firstElementOutOfView . scrollWidth ;
92- }
73+ const leftScroll = this . #container. scrollLeft + this . #container. clientWidth ;
74+ this . #container. scroll ( { left : leftScroll } ) ;
9375 this . #setOverflowState( ) ;
9476 }
9577
0 commit comments