@@ -114,25 +114,13 @@ const metadata = {
114
114
* Defines the index of the initially selected item.
115
115
* @type {Integer }
116
116
* @defaultvalue 0
117
- * @public
117
+ * @private
118
118
*/
119
- selectedIndex : {
119
+ _selectedIndex : {
120
120
type : Integer ,
121
121
defaultValue : 0 ,
122
122
} ,
123
123
124
- /**
125
- * Defines when the <code>load-more</code> event is fired. If not applied the event will not be fired.
126
- * @type {Integer }
127
- * @defaultvalue 1
128
- * @public
129
- * @since 1.0.0-rc.8
130
- */
131
- infiniteScrollOffset : {
132
- type : Integer ,
133
- defaultValue : 1 ,
134
- } ,
135
-
136
124
/**
137
125
* Defines the position of arrows.
138
126
* <br><br>
@@ -197,12 +185,12 @@ const metadata = {
197
185
events : /** @lends sap.ui.webcomponents.main.Carousel.prototype */ {
198
186
199
187
/**
200
- * Fired whenever the <code>selectedIndex</code> changes due to user interaction,
188
+ * Fired whenever the page changes due to user interaction,
201
189
* when the user clicks on the navigation arrows or while resizing,
202
190
* based on the <code>items-per-page-l</code>, <code>items-per-page-m</code> and <code>items-per-page-s</code> properties.
203
191
*
204
192
* @event
205
- * @param {Integer } selectedIndex the current <code>selectedIndex</code>.
193
+ * @param {Integer } selectedIndex the current selected index
206
194
* @public
207
195
* @since 1.0.0-rc.7
208
196
*/
@@ -211,15 +199,6 @@ const metadata = {
211
199
selectedIndex : { type : Integer } ,
212
200
} ,
213
201
} ,
214
-
215
- /**
216
- * Fired for the last items of the component if it is scrolled and the direction of scrolling is to the end.
217
- * The number of items for which the event is fired is controlled by the <code>infiniteScrollOffset</code> property.
218
- * @event sap.ui.webcomponents.main.Carousel#load-more
219
- * @public
220
- * @since 1.0.0-rc.8
221
- */
222
- "load-more" : { } ,
223
202
} ,
224
203
} ;
225
204
@@ -330,9 +309,8 @@ class Carousel extends UI5Element {
330
309
}
331
310
332
311
validateSelectedIndex ( ) {
333
- if ( ! this . isIndexInRange ( this . selectedIndex ) ) {
334
- this . selectedIndex = 0 ;
335
- console . warn ( `The "selectedIndex" is out of range, changed to: ${ 0 } ` ) ; // eslint-disable-line
312
+ if ( ! this . isIndexInRange ( this . _selectedIndex ) ) {
313
+ this . _selectedIndex = 0 ;
336
314
}
337
315
}
338
316
@@ -352,9 +330,9 @@ class Carousel extends UI5Element {
352
330
return ;
353
331
}
354
332
355
- if ( this . selectedIndex > this . pagesCount - 1 ) {
356
- this . selectedIndex = this . pagesCount - 1 ;
357
- this . fireEvent ( "navigate" , { selectedIndex : this . selectedIndex } ) ;
333
+ if ( this . _selectedIndex > this . pagesCount - 1 ) {
334
+ this . _selectedIndex = this . pagesCount - 1 ;
335
+ this . fireEvent ( "navigate" , { selectedIndex : this . _selectedIndex } ) ;
358
336
}
359
337
}
360
338
@@ -397,43 +375,50 @@ class Carousel extends UI5Element {
397
375
navigateLeft ( ) {
398
376
this . _resizing = false ;
399
377
400
- const previousSelectedIndex = this . selectedIndex ;
378
+ const previousSelectedIndex = this . _selectedIndex ;
401
379
402
- if ( this . selectedIndex - 1 < 0 ) {
380
+ if ( this . _selectedIndex - 1 < 0 ) {
403
381
if ( this . cyclic ) {
404
- this . selectedIndex = this . pagesCount - 1 ;
382
+ this . _selectedIndex = this . pagesCount - 1 ;
405
383
}
406
384
} else {
407
- -- this . selectedIndex ;
385
+ -- this . _selectedIndex ;
408
386
}
409
387
410
- if ( previousSelectedIndex !== this . selectedIndex ) {
411
- this . fireEvent ( "navigate" , { selectedIndex : this . selectedIndex } ) ;
388
+ if ( previousSelectedIndex !== this . _selectedIndex ) {
389
+ this . fireEvent ( "navigate" , { selectedIndex : this . _selectedIndex } ) ;
412
390
}
413
391
}
414
392
415
393
navigateRight ( ) {
416
394
this . _resizing = false ;
417
395
418
- const previousSelectedIndex = this . selectedIndex ;
396
+ const previousSelectedIndex = this . _selectedIndex ;
419
397
420
- if ( this . selectedIndex + 1 > this . pagesCount - 1 ) {
398
+ if ( this . _selectedIndex + 1 > this . pagesCount - 1 ) {
421
399
if ( this . cyclic ) {
422
- this . selectedIndex = 0 ;
400
+ this . _selectedIndex = 0 ;
423
401
} else {
424
402
return ;
425
403
}
426
404
} else {
427
- ++ this . selectedIndex ;
405
+ ++ this . _selectedIndex ;
428
406
}
429
407
430
- if ( previousSelectedIndex !== this . selectedIndex ) {
431
- this . fireEvent ( "navigate" , { selectedIndex : this . selectedIndex } ) ;
408
+ if ( previousSelectedIndex !== this . _selectedIndex ) {
409
+ this . fireEvent ( "navigate" , { selectedIndex : this . _selectedIndex } ) ;
432
410
}
411
+ }
433
412
434
- if ( this . pagesCount - this . selectedIndex <= this . infiniteScrollOffset + 1 ) {
435
- this . fireEvent ( "load-more" ) ;
436
- }
413
+ /**
414
+ * Changes the currently displayed page.
415
+ * @param {Integer } itemIndex The index of the target page
416
+ * @since 1.0.0-rc.15
417
+ * @public
418
+ */
419
+ navigateTo ( itemIndex ) {
420
+ this . _resizing = false ;
421
+ this . _selectedIndex = itemIndex ;
437
422
}
438
423
439
424
/**
@@ -468,7 +453,7 @@ class Carousel extends UI5Element {
468
453
}
469
454
470
455
isItemInViewport ( index ) {
471
- return index >= this . selectedIndex && index <= this . selectedIndex + this . effectiveItemsPerPage - 1 ;
456
+ return index >= this . _selectedIndex && index <= this . _selectedIndex + this . effectiveItemsPerPage - 1 ;
472
457
}
473
458
474
459
isIndexInRange ( index ) {
@@ -501,7 +486,7 @@ class Carousel extends UI5Element {
501
486
get styles ( ) {
502
487
return {
503
488
content : {
504
- transform : `translateX(${ this . _isRTL ? "" : "-" } ${ this . selectedIndex * this . _itemWidth } px` ,
489
+ transform : `translateX(${ this . _isRTL ? "" : "-" } ${ this . _selectedIndex * this . _itemWidth } px` ,
505
490
} ,
506
491
} ;
507
492
}
@@ -546,7 +531,7 @@ class Carousel extends UI5Element {
546
531
547
532
for ( let index = 0 ; index < pages ; index ++ ) {
548
533
dots . push ( {
549
- active : index === this . selectedIndex ,
534
+ active : index === this . _selectedIndex ,
550
535
ariaLabel : this . i18nBundle . getText ( CAROUSEL_DOT_TEXT , [ index + 1 ] , [ pages ] ) ,
551
536
} ) ;
552
537
}
@@ -564,11 +549,11 @@ class Carousel extends UI5Element {
564
549
}
565
550
566
551
get hasPrev ( ) {
567
- return this . cyclic || this . selectedIndex - 1 >= 0 ;
552
+ return this . cyclic || this . _selectedIndex - 1 >= 0 ;
568
553
}
569
554
570
555
get hasNext ( ) {
571
- return this . cyclic || this . selectedIndex + 1 <= this . pagesCount - 1 ;
556
+ return this . cyclic || this . _selectedIndex + 1 <= this . pagesCount - 1 ;
572
557
}
573
558
574
559
get suppressAnimation ( ) {
@@ -580,15 +565,15 @@ class Carousel extends UI5Element {
580
565
}
581
566
582
567
get selectedIndexToShow ( ) {
583
- return this . _isRTL ? this . pagesCount - ( this . pagesCount - this . selectedIndex ) + 1 : this . selectedIndex + 1 ;
568
+ return this . _isRTL ? this . pagesCount - ( this . pagesCount - this . _selectedIndex ) + 1 : this . _selectedIndex + 1 ;
584
569
}
585
570
586
571
get ofText ( ) {
587
572
return this . i18nBundle . getText ( CAROUSEL_OF_TEXT ) ;
588
573
}
589
574
590
575
get ariaActiveDescendant ( ) {
591
- return this . content . length ? `${ this . _id } -carousel-item-${ this . selectedIndex + 1 } ` : undefined ;
576
+ return this . content . length ? `${ this . _id } -carousel-item-${ this . _selectedIndex + 1 } ` : undefined ;
592
577
}
593
578
594
579
get nextPageText ( ) {
@@ -599,6 +584,24 @@ class Carousel extends UI5Element {
599
584
return this . i18nBundle . getText ( CAROUSEL_PREVIOUS_ARROW_TEXT ) ;
600
585
}
601
586
587
+ /**
588
+ * The indices of the currently visible items of the component.
589
+ * @readonly
590
+ * @since 1.0.0-rc.15
591
+ * @returns {Integer[] } the indices of the visible items
592
+ */
593
+ get visibleItemsIndices ( ) {
594
+ const visibleItemsIndices = [ ] ;
595
+
596
+ this . items . forEach ( ( item , index ) => {
597
+ if ( this . isItemInViewport ( index ) ) {
598
+ visibleItemsIndices . push ( index ) ;
599
+ }
600
+ } ) ;
601
+
602
+ return visibleItemsIndices ;
603
+ }
604
+
602
605
static get dependencies ( ) {
603
606
return [
604
607
Button ,
0 commit comments