@@ -105,9 +105,10 @@ export default class IgcCarouselComponent extends EventEmitterMixin<
105105 private static readonly increment = createCounter ( ) ;
106106 private readonly _carouselId = `igc-carousel-${ IgcCarouselComponent . increment ( ) } ` ;
107107
108+ private _paused = false ;
108109 private _lastInterval ! : ReturnType < typeof setInterval > | null ;
109110 private _hasKeyboardInteractionOnIndicators = false ;
110- private _hasMouseStop = false ;
111+ private _hasPointerInteraction = false ;
111112 private _hasInnerFocus = false ;
112113
113114 private _context = new ContextProvider ( this , {
@@ -151,9 +152,6 @@ export default class IgcCarouselComponent extends EventEmitterMixin<
151152 @state ( )
152153 private _playing = false ;
153154
154- @state ( )
155- private _paused = false ;
156-
157155 private _observerCallback ( {
158156 changes : { added, attributes } ,
159157 } : MutationControllerParams < IgcCarouselSlideComponent > ) {
@@ -329,14 +327,10 @@ export default class IgcCarouselComponent extends EventEmitterMixin<
329327
330328 addThemingController ( this , all ) ;
331329
332- addSafeEventListener ( this , 'pointerenter' , this . handlePointerEnter ) ;
333- addSafeEventListener ( this , 'pointerleave' , this . handlePointerLeave ) ;
334- addSafeEventListener ( this , 'pointerdown' , ( ) => {
335- this . _hasInnerFocus = false ;
336- } ) ;
337- addSafeEventListener ( this , 'keyup' , ( ) => {
338- this . _hasInnerFocus = true ;
339- } ) ;
330+ addSafeEventListener ( this , 'pointerenter' , this . handlePointerInteraction ) ;
331+ addSafeEventListener ( this , 'pointerleave' , this . handlePointerInteraction ) ;
332+ addSafeEventListener ( this , 'focusin' , this . handleFocusInteraction ) ;
333+ addSafeEventListener ( this , 'focusout' , this . handleFocusInteraction ) ;
340334
341335 addGesturesController ( this , {
342336 ref : this . _carouselSlidesContainerRef ,
@@ -389,42 +383,27 @@ export default class IgcCarouselComponent extends EventEmitterMixin<
389383 this . requestUpdate ( ) ;
390384 }
391385
392- private handlePointerEnter ( ) : void {
393- this . _hasMouseStop = true ;
394- if ( this . _hasInnerFocus ) {
395- return ;
396- }
397- this . handlePauseOnInteraction ( ) ;
398- }
386+ private handlePointerInteraction ( event : PointerEvent ) : void {
387+ this . _hasPointerInteraction = event . type === 'pointerenter' ;
399388
400- private handlePointerLeave ( ) : void {
401- this . _hasMouseStop = false ;
402- if ( this . _hasInnerFocus ) {
403- return ;
389+ if ( ! this . _hasInnerFocus ) {
390+ this . handlePauseOnInteraction ( ) ;
404391 }
405- this . handlePauseOnInteraction ( ) ;
406392 }
407393
408- private handleFocusIn ( ) : void {
409- if ( this . _hasInnerFocus || this . _hasMouseStop ) {
410- return ;
411- }
412- this . handlePauseOnInteraction ( ) ;
413- }
414-
415- private handleFocusOut ( event : FocusEvent ) : void {
394+ private handleFocusInteraction ( event : FocusEvent ) : void {
395+ // focusin - element that lost focus
396+ // focusout - element that gained focus
416397 const node = event . relatedTarget as Node ;
417398
418- if ( this . contains ( node ) || this . renderRoot . contains ( node ) ) {
399+ if ( this . contains ( node ) ) {
419400 return ;
420401 }
421402
422- if ( this . _hasInnerFocus ) {
423- this . _hasInnerFocus = false ;
403+ this . _hasInnerFocus = event . type === 'focusin' ;
424404
425- if ( ! this . _hasMouseStop ) {
426- this . handlePauseOnInteraction ( ) ;
427- }
405+ if ( ! this . _hasPointerInteraction ) {
406+ this . handlePauseOnInteraction ( ) ;
428407 }
429408 }
430409
@@ -789,7 +768,7 @@ export default class IgcCarouselComponent extends EventEmitterMixin<
789768
790769 protected override render ( ) {
791770 return html `
792- < section @focusin = ${ this . handleFocusIn } @focusout = ${ this . handleFocusOut } >
771+ < section >
793772 ${ this . hideNavigation ? nothing : this . navigationTemplate ( ) }
794773 ${ this . hideIndicators || this . showIndicatorsLabel
795774 ? nothing
@@ -800,7 +779,7 @@ export default class IgcCarouselComponent extends EventEmitterMixin<
800779 < div
801780 ${ ref ( this . _carouselSlidesContainerRef ) }
802781 id =${ this . _carouselId }
803- aria-live =${ this . interval && this . isPlaying ? 'off' : 'polite' }
782+ aria-live =${ this . interval && this . _playing ? 'off' : 'polite' }
804783 >
805784 < slot @slotchange =${ this . handleSlotChange } > </ slot >
806785 </ div >
0 commit comments