@@ -42,7 +42,12 @@ export class OverflowController implements ReactiveController {
4242 }
4343 this . overflowLeft = ! this . #hideOverflowButtons && ! isElementInView ( this . #container, this . firstItem ) ;
4444 this . overflowRight = ! this . #hideOverflowButtons && ! isElementInView ( this . #container, this . lastItem ) ;
45- this . showScrollButtons = ! this . #hideOverflowButtons && ( this . overflowLeft || this . overflowRight ) ;
45+ let scrollButtonsWidth = 0 ;
46+ if ( this . overflowLeft || this . overflowRight ) {
47+ scrollButtonsWidth = ( this . #container. parentElement ?. querySelector ( 'button' ) ?. getBoundingClientRect ( ) . width || 0 ) * 2 ;
48+ }
49+ this . showScrollButtons = ! this . #hideOverflowButtons &&
50+ this . #container. scrollWidth > ( this . #container. clientWidth + scrollButtonsWidth ) ;
4651 this . host . requestUpdate ( ) ;
4752 }
4853
@@ -61,35 +66,17 @@ export class OverflowController implements ReactiveController {
6166 if ( ! this . #container) {
6267 return ;
6368 }
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- }
69+ const leftScroll = this . #container. scrollLeft - this . #container. clientWidth ;
70+ this . #container. scroll ( { left : leftScroll , behavior : 'smooth' } ) ;
7571 this . #setOverflowState( ) ;
7672 }
7773
7874 scrollRight ( ) {
7975 if ( ! this . #container) {
8076 return ;
8177 }
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- }
78+ const leftScroll = this . #container. scrollLeft + this . #container. clientWidth ;
79+ this . #container. scroll ( { left : leftScroll , behavior : 'smooth' } ) ;
9380 this . #setOverflowState( ) ;
9481 }
9582
0 commit comments