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(module:icon): fix icon classname writeback #2259

Merged
merged 1 commit into from
Oct 10, 2018
Merged
Show file tree
Hide file tree
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
24 changes: 9 additions & 15 deletions components/icon/nz-icon.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ export class NzIconDirective extends IconDirective implements OnInit, OnChanges,
if (this.type !== anticonType) {
this.type = anticonType;
this._changeIcon()
.then(svg => {
this._addExtraModifications(svg);
})
.catch(err => {
console.warn('[NG-ZORRO]', `You can find more about this error on http://ng.ant.design/components/icon/en\n`, err);
});
.then(svg => {
this._addExtraModifications(svg);
})
.catch(err => {
console.warn('[NG-ZORRO]', `You can find more about this error on http://ng.ant.design/components/icon/en\n`, err);
});
}
}

Expand All @@ -100,13 +100,7 @@ export class NzIconDirective extends IconDirective implements OnInit, OnChanges,

private _getIconNameBack(): void {
if (typeof this.type === 'string') {
let back = '';
if (this.theme && this.theme !== 'outline' && !this.type.endsWith('-o')) {
back = `anticon-${withSuffix(this.type, this.theme)}`;
} else {
back = `anticon-${this.type}`;
}
this._renderer.addClass(this._elementRef.nativeElement, back);
this._renderer.addClass(this._elementRef.nativeElement, `anticon-${this.type}`);
}
}

Expand Down Expand Up @@ -137,8 +131,8 @@ export class NzIconDirective extends IconDirective implements OnInit, OnChanges,
this._classChangeHandler(this._el.className);
this._classNameObserver = new MutationObserver((mutations: MutationRecord[]) => {
mutations
.filter((mutation: MutationRecord) => mutation.attributeName === 'class')
.forEach((mutation: MutationRecord) => this._classChangeHandler((mutation.target as HTMLElement).className));
.filter((mutation: MutationRecord) => mutation.attributeName === 'class')
.forEach((mutation: MutationRecord) => this._classChangeHandler((mutation.target as HTMLElement).className));
});
this._classNameObserver.observe(this._elementRef.nativeElement, { attributes: true });
}
Expand Down
10 changes: 8 additions & 2 deletions components/icon/nz-icon.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CommonModule } from '@angular/common';
import { Component } from '@angular/core';
import { async, fakeAsync, flush, tick, TestBed } from '@angular/core/testing';
import { async, fakeAsync, tick, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { LoadingOutline, QuestionCircleOutline, QuestionOutline } from '@ant-design/icons-angular/icons';
import { NzIconDirective } from './nz-icon.directive';
Expand All @@ -19,13 +19,19 @@ describe('icon', () => {
}).compileComponents();
});

describe('expansions', () => {
describe('extensions', () => {
beforeEach(() => {
fixture = TestBed.createComponent(NzTestIconComponent);
testComponent = fixture.debugElement.componentInstance;
icons = fixture.debugElement.queryAll(By.directive(NzIconDirective));
});

it('should get icon class name back', fakeAsync(() => {
fixture.detectChanges();
expect(icons[ 0 ].nativeElement.classList.contains('anticon-question'));
expect(icons[ 1 ].nativeElement.classList.contains('anticon-loading'));
}));

it('should support spin and cancel', fakeAsync(() => {
fixture.detectChanges();
tick(1000);
Expand Down