added visibility filter for tab widget

This commit is contained in:
Vito Albano
2016-10-14 14:20:31 +01:00
parent b73ba81456
commit 8fb437e7d2
2 changed files with 18 additions and 6 deletions

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { Component, Input, AfterViewInit, EventEmitter, Output } from '@angular/core';
import { Component, Input, AfterViewInit, AfterContentChecked, EventEmitter, Output } from '@angular/core';
import { TabModel, FormFieldModel } from './../core/index';
@Component({
@@ -23,7 +23,7 @@ import { TabModel, FormFieldModel } from './../core/index';
selector: 'tabs-widget',
templateUrl: './tabs.widget.html'
})
export class TabsWidget implements AfterViewInit {
export class TabsWidget implements AfterContentChecked, AfterViewInit {
@Input()
tabs: TabModel[] = [];
@@ -31,14 +31,26 @@ export class TabsWidget implements AfterViewInit {
@Output()
formTabChanged: EventEmitter<FormFieldModel> = new EventEmitter<FormFieldModel>();
visibleTabs: TabModel[] = [];
hasTabs() {
return this.tabs && this.tabs.length > 0;
}
ngAfterContentChecked() {
this.filterVisibleTabs();
}
ngAfterViewInit() {
this.setupMaterialComponents();
}
filterVisibleTabs() {
this.visibleTabs = this.tabs.filter(tab => {
return tab.isVisible;
});
}
setupMaterialComponents(): boolean {
// workaround for MDL issues with dynamic components
if (componentHandler) {
@@ -48,8 +60,8 @@ export class TabsWidget implements AfterViewInit {
return false;
}
tabChanged( field: FormFieldModel ) {
this.formTabChanged.emit(field);
tabChanged(field: FormFieldModel) {
this.formTabChanged.emit(field);
}
}