Skip to content

Commit c9c7745

Browse files
MOBILE-3284 Accessibility - Page through course page tabs
1 parent ad85ded commit c9c7745

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
@@ -83,6 +83,7 @@ export class CoreTabsComponent implements OnInit, AfterViewInit, OnChanges, OnDe
8383
protected firstSelectedTab: number;
8484
protected unregisterBackButtonAction: any;
8585
protected languageChangedSubscription: Subscription;
86+
protected isInTransition = false; // Weather Slides is in transition.
8687

8788
constructor(element: ElementRef, protected content: Content, protected domUtils: CoreDomUtilsProvider,
8889
protected appProvider: CoreAppProvider, platform: Platform, translate: TranslateService) {
@@ -319,6 +320,7 @@ export class CoreTabsComponent implements OnInit, AfterViewInit, OnChanges, OnDe
319320
*/
320321
slideChanged(): void {
321322
const currentIndex = this.slides.getActiveIndex();
323+
this.isInTransition = false;
322324
if (this.slidesShown >= this.numTabsShown) {
323325
this.showPrevButton = false;
324326
this.showNextButton = false;
@@ -391,20 +393,61 @@ export class CoreTabsComponent implements OnInit, AfterViewInit, OnChanges, OnDe
391393
}
392394

393395
/**
394-
* Method that shows the next slide.
396+
* Method that shows the next page.
395397
*/
396398
slideNext(): void {
397399
if (this.showNextButton) {
398-
this.slides.slideNext();
400+
// Stop if slides are in transition.
401+
if (this.isInTransition)
402+
return;
403+
404+
if (this.slides.isBeginning()) {
405+
// Slide to the second page.
406+
this.slides.slideTo(this.maxSlides);
407+
} else {
408+
const currentIndex = this.slides.getActiveIndex();
409+
if (typeof currentIndex !== 'undefined') {
410+
const nextSlideIndex = currentIndex + this.maxSlides;
411+
this.isInTransition = true;
412+
if (nextSlideIndex < this.numTabsShown) {
413+
// Slide to the next page.
414+
this.slides.slideTo(nextSlideIndex);
415+
} else {
416+
// Slide to the latest slide.
417+
this.slides.slideTo(this.numTabsShown - 1);
418+
}
419+
}
420+
421+
}
399422
}
400423
}
401424

402425
/**
403-
* Method that shows the previous slide.
426+
* Method that shows the previous page.
404427
*/
405428
slidePrev(): void {
406429
if (this.showPrevButton) {
407-
this.slides.slidePrev();
430+
// Stop if slides are in transition.
431+
if (this.isInTransition)
432+
return;
433+
434+
if (this.slides.isEnd()) {
435+
this.slides.slideTo(this.numTabsShown - this.maxSlides * 2);
436+
// Slide to the previous of the latest page.
437+
} else {
438+
const currentIndex = this.slides.getActiveIndex();
439+
if (typeof currentIndex !== 'undefined') {
440+
const prevSlideIndex = currentIndex - this.maxSlides;
441+
this.isInTransition = true;
442+
if (prevSlideIndex >= 0) {
443+
// Slide to the previous page.
444+
this.slides.slideTo(prevSlideIndex);
445+
} else {
446+
// Slide to the first page.
447+
this.slides.slideTo(0);
448+
}
449+
}
450+
}
408451
}
409452
}
410453

0 commit comments

Comments
 (0)