@@ -52,7 +52,7 @@ import { all } from './themes/container.js';
5252import { styles as shared } from './themes/shared/carousel.common.css.js' ;
5353
5454export interface IgcCarouselComponentEventMap {
55- igcSlideChanged : CustomEvent < void > ;
55+ igcSlideChanged : CustomEvent < number > ;
5656 igcPlaying : CustomEvent < void > ;
5757 igcPaused : CustomEvent < void > ;
5858}
@@ -243,7 +243,7 @@ export default class IgcCarouselComponent extends EventEmitterMixin<
243243 * @attr interval
244244 */
245245 @property ( { type : Number , reflect : false } )
246- public interval ! : number ;
246+ public interval : number | undefined ;
247247
248248 /**
249249 * Controls the maximum indicator controls (dots) that can be shown. Default value is `10`.
@@ -263,6 +263,7 @@ export default class IgcCarouselComponent extends EventEmitterMixin<
263263 @property ( { attribute : 'animation-type' } )
264264 public animationType : 'slide' | 'fade' | 'none' = 'slide' ;
265265
266+ /* blazorSuppress */
266267 /**
267268 * The slides of the carousel.
268269 */
@@ -505,7 +506,7 @@ export default class IgcCarouselComponent extends EventEmitterMixin<
505506 }
506507
507508 await callback . call ( this ) ;
508- this . emitEvent ( 'igcSlideChanged' ) ;
509+ this . emitEvent ( 'igcSlideChanged' , { detail : this . current } ) ;
509510
510511 if ( this . interval ) {
511512 this . restartInterval ( ) ;
@@ -553,7 +554,7 @@ export default class IgcCarouselComponent extends EventEmitterMixin<
553554 this . _lastInterval = setInterval ( ( ) => {
554555 if ( this . isPlaying && this . total ) {
555556 this . next ( ) ;
556- this . emitEvent ( 'igcSlideChanged' ) ;
557+ this . emitEvent ( 'igcSlideChanged' , { detail : this . current } ) ;
557558 } else {
558559 this . pause ( ) ;
559560 }
@@ -606,7 +607,7 @@ export default class IgcCarouselComponent extends EventEmitterMixin<
606607 }
607608
608609 /**
609- * Switches to the next slide running any animations and returns if the operation was a success .
610+ * Switches to the next slide, runs any animations, and returns if the operation was successful .
610611 */
611612 public async next ( ) : Promise < boolean > {
612613 if ( this . disableLoop && this . nextIndex === 0 ) {
@@ -618,7 +619,7 @@ export default class IgcCarouselComponent extends EventEmitterMixin<
618619 }
619620
620621 /**
621- * Switches to the previous slide running any animations and returns if the operation was a success .
622+ * Switches to the previous slide, runs any animations, and returns if the operation was successful .
622623 */
623624 public async prev ( ) : Promise < boolean > {
624625 if ( this . disableLoop && this . prevIndex === this . total - 1 ) {
@@ -629,20 +630,41 @@ export default class IgcCarouselComponent extends EventEmitterMixin<
629630 return await this . select ( this . slides [ this . prevIndex ] , 'prev' ) ;
630631 }
631632
633+ /* blazorSuppress */
632634 /**
633- * Switches the passed in slide running any animations and returns if the operation was a success .
635+ * Switches to the passed- in slide, runs any animations, and returns if the operation was successful .
634636 */
635637 public async select (
636638 slide : IgcCarouselSlideComponent ,
637- direction ?: 'next' | 'prev'
639+ animationDirection ?: 'next' | 'prev'
640+ ) : Promise < boolean > ;
641+ /**
642+ * Switches to slide by index, runs any animations, and returns if the operation was successful.
643+ */
644+ public async select (
645+ index : number ,
646+ animationDirection ?: 'next' | 'prev'
647+ ) : Promise < boolean > ;
648+ public async select (
649+ slideOrIndex : IgcCarouselSlideComponent | number ,
650+ animationDirection ?: 'next' | 'prev'
638651 ) : Promise < boolean > {
639- const index = this . slides . indexOf ( slide ) ;
652+ let index : number ;
653+ let slide : IgcCarouselSlideComponent | undefined ;
654+
655+ if ( typeof slideOrIndex === 'number' ) {
656+ index = slideOrIndex ;
657+ slide = this . slides . at ( index ) ;
658+ } else {
659+ slide = slideOrIndex ;
660+ index = this . slides . indexOf ( slide ) ;
661+ }
640662
641- if ( index === this . current || index === - 1 ) {
663+ if ( index === this . current || index === - 1 || ! slide ) {
642664 return false ;
643665 }
644666
645- const dir = direction ?? ( index > this . current ? 'next' : 'prev' ) ;
667+ const dir = animationDirection ?? ( index > this . current ? 'next' : 'prev' ) ;
646668
647669 await this . animateSlides ( slide , this . _activeSlide , dir ) ;
648670 return true ;
0 commit comments