@@ -8,6 +8,7 @@ import './OverflowScroller.scss';
88
99const b = block ( 'overflow-scroller' ) ;
1010const TRANSITION_TIME = 300 ;
11+ const PADDING_SIZE = 24 ;
1112
1213type Arrow = 'left' | 'right' ;
1314
@@ -27,7 +28,7 @@ export default class OverflowScroller extends React.Component<
2728 OverflowScrollerState
2829> {
2930 state = {
30- arrows : [ ] ,
31+ arrows : [ ] as Arrow [ ] ,
3132 scrollValue : 0 ,
3233 } ;
3334 containerRef = createRef < HTMLDivElement > ( ) ;
@@ -57,16 +58,25 @@ export default class OverflowScroller extends React.Component<
5758 const { className, children} = this . props ;
5859 const { arrows, scrollValue} = this . state ;
5960 const wrapperStyle = arrows . length ? { left : - scrollValue } : { left : 0 } ;
61+ const paddingLeft = arrows . includes ( 'left' ) ;
62+ const paddingRight = arrows . includes ( 'right' ) ;
6063
6164 return (
62- < div className = { b ( null , className ) } ref = { this . containerRef } >
63- < div className = { b ( 'wrapper' ) } style = { wrapperStyle } ref = { this . wrapperRef } >
64- { children }
65+ < div
66+ className = { b ( 'container' , {
67+ 'padding-left' : paddingLeft ,
68+ 'padding-right' : paddingRight ,
69+ } ) }
70+ >
71+ < div className = { b ( null , className ) } ref = { this . containerRef } >
72+ < div className = { b ( 'wrapper' ) } style = { wrapperStyle } ref = { this . wrapperRef } >
73+ { children }
74+ </ div >
6575 </ div >
6676 { arrows . map ( ( direction : Arrow ) => (
6777 < div
6878 key = { direction }
69- className = { b ( 'scroller ' , { type : direction } ) }
79+ className = { b ( 'arrow ' , { type : direction } ) }
7080 onClick = { ( e : React . MouseEvent ) => this . handleScrollClick ( e , direction ) }
7181 >
7282 < ToggleArrow size = { 18 } type = { 'horizontal' } iconType = "navigation" />
@@ -94,7 +104,7 @@ export default class OverflowScroller extends React.Component<
94104 } , 100 ) ;
95105
96106 private handleScrollClick = ( e : React . MouseEvent , arrow : Arrow ) => {
97- const { scrollValue} = this . state ;
107+ const { scrollValue, arrows } = this . state ;
98108 const { onScrollStart} = this . props ;
99109
100110 if (
@@ -107,8 +117,11 @@ export default class OverflowScroller extends React.Component<
107117 const wrapperWidth = this . wrapperRef . current . offsetWidth ;
108118 const hiddenWidth =
109119 arrow === 'right' ? wrapperWidth - ( containerWidth + scrollValue ) : scrollValue ;
120+ const padding =
121+ arrows . length > 1 && hiddenWidth + PADDING_SIZE > containerWidth ? PADDING_SIZE : 0 ;
110122 const delta = containerWidth > hiddenWidth ? hiddenWidth : containerWidth ;
111- const newScrollValue = arrow === 'right' ? scrollValue + delta : scrollValue - delta ;
123+ const newScrollValue =
124+ arrow === 'right' ? scrollValue + delta + padding : scrollValue - delta - padding ;
112125 let newArrows : Arrow [ ] = [ 'left' , 'right' ] ;
113126
114127 if ( newScrollValue + containerWidth >= wrapperWidth ) {
0 commit comments