Skip to content

Commit cf6d7b0

Browse files
authored
Merge pull request #2276 from nguyenphuctien/MOBILE-3284_integration
MOBILE-3284 Accessibility - Page through course page tabs
2 parents 4e52e31 + c9c7745 commit cf6d7b0

File tree

1 file changed

+47
-4
lines changed

1 file changed

+47
-4
lines changed

src/components/tabs/tabs.ts

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export class CoreTabsComponent implements OnInit, AfterViewInit, OnChanges, OnDe
9090
protected firstSelectedTab: number;
9191
protected unregisterBackButtonAction: any;
9292
protected languageChangedSubscription: Subscription;
93+
protected isInTransition = false; // Weather Slides is in transition.
9394

9495
constructor(element: ElementRef, protected content: Content, protected domUtils: CoreDomUtilsProvider,
9596
protected appProvider: CoreAppProvider, private configProvider: CoreConfigProvider, platform: Platform,
@@ -328,6 +329,7 @@ export class CoreTabsComponent implements OnInit, AfterViewInit, OnChanges, OnDe
328329
*/
329330
slideChanged(): void {
330331
const currentIndex = this.slides.getActiveIndex();
332+
this.isInTransition = false;
331333
if (this.slidesShown >= this.numTabsShown) {
332334
this.showPrevButton = false;
333335
this.showNextButton = false;
@@ -407,20 +409,61 @@ export class CoreTabsComponent implements OnInit, AfterViewInit, OnChanges, OnDe
407409
}
408410

409411
/**
410-
* Method that shows the next slide.
412+
* Method that shows the next page.
411413
*/
412414
slideNext(): void {
413415
if (this.showNextButton) {
414-
this.slides.slideNext();
416+
// Stop if slides are in transition.
417+
if (this.isInTransition)
418+
return;
419+
420+
if (this.slides.isBeginning()) {
421+
// Slide to the second page.
422+
this.slides.slideTo(this.maxSlides);
423+
} else {
424+
const currentIndex = this.slides.getActiveIndex();
425+
if (typeof currentIndex !== 'undefined') {
426+
const nextSlideIndex = currentIndex + this.maxSlides;
427+
this.isInTransition = true;
428+
if (nextSlideIndex < this.numTabsShown) {
429+
// Slide to the next page.
430+
this.slides.slideTo(nextSlideIndex);
431+
} else {
432+
// Slide to the latest slide.
433+
this.slides.slideTo(this.numTabsShown - 1);
434+
}
435+
}
436+
437+
}
415438
}
416439
}
417440

418441
/**
419-
* Method that shows the previous slide.
442+
* Method that shows the previous page.
420443
*/
421444
slidePrev(): void {
422445
if (this.showPrevButton) {
423-
this.slides.slidePrev();
446+
// Stop if slides are in transition.
447+
if (this.isInTransition)
448+
return;
449+
450+
if (this.slides.isEnd()) {
451+
this.slides.slideTo(this.numTabsShown - this.maxSlides * 2);
452+
// Slide to the previous of the latest page.
453+
} else {
454+
const currentIndex = this.slides.getActiveIndex();
455+
if (typeof currentIndex !== 'undefined') {
456+
const prevSlideIndex = currentIndex - this.maxSlides;
457+
this.isInTransition = true;
458+
if (prevSlideIndex >= 0) {
459+
// Slide to the previous page.
460+
this.slides.slideTo(prevSlideIndex);
461+
} else {
462+
// Slide to the first page.
463+
this.slides.slideTo(0);
464+
}
465+
}
466+
}
424467
}
425468
}
426469

0 commit comments

Comments
 (0)