Skip to content

Commit

Permalink
fix(tabs): fix customClass [fixes #2253] (#2273)
Browse files Browse the repository at this point in the history
* fix(tabs): fix customClass [fixes #2253]

* fix(tabs): fix removing of old custom class
  • Loading branch information
IlyaSurmay authored and valorkin committed Jul 27, 2017
1 parent eb3cd04 commit 0d67ef8
Showing 1 changed file with 19 additions and 4 deletions.
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

0 comments on commit 0d67ef8

Please sign in to comment.