Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tabs): fix customClass [fixes #2253] #2273

Merged
merged 3 commits into from
Jul 27, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/tabs/tab.directive.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
Directive, EventEmitter, HostBinding, Input, Output, TemplateRef, OnInit, OnDestroy, ElementRef } from '@angular/core';
Directive, EventEmitter, HostBinding, Input, Output, TemplateRef, OnInit, OnDestroy, ElementRef, Renderer } from '@angular/core';
import { TabsetComponent } from './tabset.component';

@Directive({selector: 'tab, [tab]'})
Expand All @@ -13,15 +13,29 @@ export class TabDirective implements OnInit, OnDestroy {
/** if true tab can be removable, additional button will appear */
@Input() public removable: boolean;
/** if set, will be added to the tab's class atribute */
@Input() public customClass: string;
@Input() public get customClass(): string {
return this._customClass;
}

public set customClass(customClass: string) {
if (this._customClass && this._customClass !== customClass) {
this.renderer.setElementClass(this.elementRef.nativeElement, this._customClass, false);
}

this._customClass = customClass;

if (this._customClass) {
this.renderer.setElementClass(this.elementRef.nativeElement, this._customClass, true);
}
}

/** tab active state toggle */
@HostBinding('class.active')
@Input()
public get active(): boolean {
return this._active;
}

public set active(active: boolean) {
if (this.disabled && active || !active) {
if (!active) {
Expand Down Expand Up @@ -53,8 +67,9 @@ export class TabDirective implements OnInit, OnDestroy {
public headingRef: TemplateRef<any>;
public tabset: TabsetComponent;
protected _active: boolean;
protected _customClass: string;

public constructor(tabset: TabsetComponent, public elementRef: ElementRef) {
public constructor(tabset: TabsetComponent, public elementRef: ElementRef, public renderer: Renderer) {
this.tabset = tabset;
this.tabset.addTab(this);
}
Expand Down