File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -777,4 +777,26 @@ describe("Carousel general interaction", () => {
777777
778778 cy . get ( "#outsideButton" ) . should ( "be.focused" ) ;
779779 } ) ;
780+
781+ it ( "visibleItemsIndices should not contain negative values when initial items < itemsPerPage" , ( ) => {
782+ cy . mount (
783+ < Carousel id = "dynamicCarousel" itemsPerPage = "S1 M2 L3 XL4" >
784+ < Card > Card 1</ Card >
785+ < Card > Card 2</ Card >
786+ </ Carousel >
787+ ) ;
788+
789+ cy . viewport ( 1200 , 500 ) ;
790+
791+ cy . get ( "#dynamicCarousel" )
792+ . shadow ( )
793+ . find ( ".ui5-carousel-item:not(.ui5-carousel-item--hidden)" )
794+ . should ( "have.length" , 2 ) ;
795+
796+ cy . get < Carousel > ( "#dynamicCarousel" )
797+ . then ( $carousel => {
798+ const indices = $carousel [ 0 ] . visibleItemsIndices ;
799+ expect ( indices . every ( i => i >= 0 ) , "visibleItemsIndices should not contain negative values" ) . to . be . true ;
800+ } ) ;
801+ } ) ;
780802} ) ;
Original file line number Diff line number Diff line change @@ -785,7 +785,7 @@ class Carousel extends UI5Element {
785785 }
786786
787787 if ( newItemIndex > items . length - effectiveItemsPerPage ) {
788- newItemIndex = items . length - effectiveItemsPerPage ;
788+ newItemIndex = Math . max ( 0 , items . length - effectiveItemsPerPage ) ;
789789 }
790790 const lastItemIndex = newItemIndex + effectiveItemsPerPage ;
791791
You can’t perform that action at this time.
0 commit comments