Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
Fixed tabset index out of order (#1738)
Browse files Browse the repository at this point in the history
  • Loading branch information
blackbaud-conorwright authored and Blackbaud-SteveBrush committed Jun 29, 2018
1 parent 1d7aae7 commit a3fbf7e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/modules/tabs/fixtures/tabset.component.fixture.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { Component } from '@angular/core';
import {
Component,
ViewChild
} from '@angular/core';
import {
SkyTabsetComponent
} from '..';

@Component({
selector: 'sky-test-cmp',
Expand Down Expand Up @@ -29,6 +35,9 @@ export class TabsetTestComponent {

public tabMaxWidth = 2000;

@ViewChild(SkyTabsetComponent)
public tabsetComponent: SkyTabsetComponent;

public newTab() { }

public openTab() { }
Expand Down
9 changes: 6 additions & 3 deletions src/modules/tabs/tab.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
Input,
OnDestroy,
Output,
AfterViewInit,
ChangeDetectorRef,
OnChanges,
SimpleChanges
Expand All @@ -16,7 +15,7 @@ import { SkyTabsetService } from './tabset.service';
selector: 'sky-tab',
templateUrl: './tab.component.html'
})
export class SkyTabComponent implements OnDestroy, AfterViewInit, OnChanges {
export class SkyTabComponent implements OnDestroy, OnChanges {
@Input()
public tabHeading: string;

Expand All @@ -41,7 +40,7 @@ export class SkyTabComponent implements OnDestroy, AfterViewInit, OnChanges {

constructor(private tabsetService: SkyTabsetService, private ref: ChangeDetectorRef) {}

public ngAfterViewInit() {
public initializeTabIndex() {
setTimeout(() => {
this.tabsetService.addTab(this);

Expand Down Expand Up @@ -69,9 +68,13 @@ export class SkyTabComponent implements OnDestroy, AfterViewInit, OnChanges {
this.tabsetService.activateTab(this);
}
}

}

public ngOnDestroy() {

this.tabsetService.destroyTab(this);

}

}
11 changes: 11 additions & 0 deletions src/modules/tabs/tabset.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ describe('Tabset component', () => {
}
}

it('should initialize tabs in proper order', fakeAsync(() => {
let fixture = TestBed.createComponent(TabsetTestComponent);
fixture.detectChanges();
tick();
let tabsetService: SkyTabsetService = (fixture.componentInstance.tabsetComponent as any).tabsetService;

fixture.componentInstance.tabsetComponent.tabs.forEach((item, index) => {
expect(item).toBe(tabsetService.tabs.getValue()[index]);
});
}));

describe('tabs with active attribute', () => {
it('should change the active tab when tab active is set to true', fakeAsync(() => {
let fixture = TestBed.createComponent(TabsetTestComponent);
Expand Down
3 changes: 3 additions & 0 deletions src/modules/tabs/tabset.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ export class SkyTabsetComponent
}

public ngAfterContentInit() {
// initialize each tab's index. (in case tabs are instantiated out of order)
this.tabs.forEach(item => item.initializeTabIndex());

if (this.active || this.active === 0) {
this.tabsetService.activateTabIndex(this.active);
}
Expand Down

0 comments on commit a3fbf7e

Please sign in to comment.