Skip to content

Commit 495852d

Browse files
zdrawkukdinev
andauthored
fix(carousel): Focus on leaveAnimation done #9329 - 11.1.x (#9454)
* fix(carousel): focus on leaveAnimation done #9329 Co-authored-by: Konstantin Dinev <[email protected]>
1 parent 194fa98 commit 495852d

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

projects/igniteui-angular/src/lib/carousel/carousel.component.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ export class IgxCarouselComponent implements OnDestroy, AfterContentInit {
563563
if (this.keyboardSupport) {
564564
event.preventDefault();
565565
this.next();
566-
requestAnimationFrame(() => this.slides.find(s => s.active).nativeElement.focus());
566+
this.focusSlideElement();
567567
}
568568
}
569569

@@ -573,7 +573,7 @@ export class IgxCarouselComponent implements OnDestroy, AfterContentInit {
573573
if (this.keyboardSupport) {
574574
event.preventDefault();
575575
this.prev();
576-
requestAnimationFrame(() => this.slides.find(s => s.active).nativeElement.focus());
576+
this.focusSlideElement();
577577
}
578578
}
579579

@@ -599,7 +599,7 @@ export class IgxCarouselComponent implements OnDestroy, AfterContentInit {
599599
if (this.keyboardSupport && this.slides.length > 0) {
600600
event.preventDefault();
601601
this.slides.first.active = true;
602-
requestAnimationFrame(() => this.slides.find(s => s.active).nativeElement.focus());
602+
this.focusSlideElement();
603603
}
604604
}
605605

@@ -609,7 +609,7 @@ export class IgxCarouselComponent implements OnDestroy, AfterContentInit {
609609
if (this.keyboardSupport && this.slides.length > 0) {
610610
event.preventDefault();
611611
this.slides.last.active = true;
612-
requestAnimationFrame(() => this.slides.find(s => s.active).nativeElement.focus());
612+
this.focusSlideElement();
613613
}
614614
}
615615

@@ -1125,6 +1125,16 @@ export class IgxCarouselComponent implements OnDestroy, AfterContentInit {
11251125
});
11261126
}
11271127
}
1128+
private focusSlideElement() {
1129+
if (this.leaveAnimationPlayer) {
1130+
this.leaveAnimationPlayer.onDone(() => {
1131+
this.slides.find(s => s.active).nativeElement.focus();
1132+
});
1133+
} else {
1134+
requestAnimationFrame(() => this.slides.find(s => s.active).nativeElement.focus());
1135+
}
1136+
}
1137+
11281138
}
11291139

11301140
export interface ISlideEventArgs extends IBaseEventArgs {

src/app/carousel/carousel.sample.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ export class CarouselSampleComponent {
2222

2323
public addNewSlide() {
2424
this.slides.push(
25-
{image: 'assets/images/carousel/[email protected]'},
26-
{image: 'assets/images/carousel/[email protected]'},
27-
{image: 'assets/images/carousel/[email protected]'}
25+
{image: 'assets/images/carousel/[email protected]', active: true},
26+
{image: 'assets/images/carousel/[email protected]', active: false},
27+
{image: 'assets/images/carousel/[email protected]', active: false}
2828
);
2929
}
3030

0 commit comments

Comments
 (0)