@@ -595,25 +595,45 @@ class Carousel extends UI5Element {
595595 }
596596
597597 async navigateLeft ( ) {
598- this . focusItemIndex ( this . _focusedItemIndex - 1 ) ;
598+ let newFocusedItemIndex = this . _focusedItemIndex - 1 ;
599+ if ( this . cyclic && newFocusedItemIndex < 0 ) {
600+ newFocusedItemIndex = this . items . length - 1 ;
601+ }
602+
603+ this . focusItemIndex ( newFocusedItemIndex ) ;
599604 await renderFinished ( ) ;
600605 this . focusItem ( ) ;
601606 }
602607
603608 async navigateRight ( ) {
604- this . focusItemIndex ( this . _focusedItemIndex + 1 ) ;
609+ let newFocusedItemIndex = this . _focusedItemIndex + 1 ;
610+ if ( this . cyclic && newFocusedItemIndex > this . items . length - 1 ) {
611+ newFocusedItemIndex = 0 ;
612+ }
613+
614+ this . focusItemIndex ( newFocusedItemIndex ) ;
605615 await renderFinished ( ) ;
606616 this . focusItem ( ) ;
607617 }
608618
609619 async navigateArrowRight ( ) {
610- this . navigateTo ( this . _currentSlideIndex + 1 ) ;
620+ let newCurrentSlideIndex = this . _currentSlideIndex + 1 ;
621+ if ( this . cyclic && newCurrentSlideIndex > this . items . length - this . effectiveItemsPerPage ) {
622+ newCurrentSlideIndex = 0 ;
623+ }
624+
625+ this . navigateTo ( newCurrentSlideIndex ) ;
611626 await renderFinished ( ) ;
612627 this . focusItem ( ) ;
613628 }
614629
615630 async navigateArrowLeft ( ) {
616- this . navigateTo ( this . _currentSlideIndex - 1 ) ;
631+ let newCurrentSlideIndex = this . _currentSlideIndex - 1 ;
632+ if ( this . cyclic && newCurrentSlideIndex < 0 ) {
633+ newCurrentSlideIndex = this . items . length - 1 ;
634+ }
635+
636+ this . navigateTo ( newCurrentSlideIndex ) ;
617637 await renderFinished ( ) ;
618638 this . focusItem ( ) ;
619639 }
@@ -624,18 +644,11 @@ class Carousel extends UI5Element {
624644
625645 _navButtonClick ( e : UI5CustomEvent < Icon , "click" > ) {
626646 const target = e . target as Icon ;
627- if ( this . _visibleItemsIndexes . length > 1 ) {
628- if ( target . hasAttribute ( "data-ui5-arrow-forward" ) ) {
629- this . navigateArrowRight ( ) ;
630- } else {
631- this . navigateArrowLeft ( ) ;
632- }
633- } else if ( this . _visibleItemsIndexes . length <= 1 ) {
634- if ( target . hasAttribute ( "data-ui5-arrow-forward" ) ) {
635- this . navigateRight ( ) ;
636- } else {
637- this . navigateLeft ( ) ;
638- }
647+
648+ if ( target . hasAttribute ( "data-ui5-arrow-forward" ) ) {
649+ this . navigateArrowRight ( ) ;
650+ } else {
651+ this . navigateArrowLeft ( ) ;
639652 }
640653 }
641654
0 commit comments