Skip to content

Commit

Permalink
fix(module:tag): fix default color when empty color values (#1256)
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk authored and vthinkxie committed Apr 4, 2018
1 parent 7b3d70c commit ba3a323
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 3 additions & 2 deletions components/tag/nz-tag.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,11 @@ export class NzTagComponent implements OnInit, AfterViewInit {
}

updateClassMap(): void {
const isPresetColor = this.isPresetColor(this.nzColor);
this.classMap = {
[ `ant-tag` ] : true,
[ `ant-tag-has-color` ] : this.isPreset === false,
[ `ant-tag-${this.nzColor}` ] : this.isPreset === true,
[ `ant-tag-has-color` ] : this.nzColor && !isPresetColor,
[ `ant-tag-${this.nzColor}` ] : isPresetColor,
[ `ant-tag-checkable` ] : this.nzMode === 'checkable',
[ `ant-tag-checkable-checked` ]: this.nzChecked
};
Expand Down
13 changes: 12 additions & 1 deletion components/tag/nz-tag.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('tag', () => {
}));
it('should color work', () => {
fixture.detectChanges();
expect(tag.nativeElement.firstElementChild.classList).toContain('ant-tag-has-color');
expect(tag.nativeElement.firstElementChild.classList).not.toContain('ant-tag-has-color');
testComponent.color = 'green';
fixture.detectChanges();
expect(tag.nativeElement.firstElementChild.classList).toContain('ant-tag-green');
Expand All @@ -73,6 +73,17 @@ describe('tag', () => {
expect(tag.nativeElement.firstElementChild.classList).toContain('ant-tag-green');
expect(tag.nativeElement.firstElementChild.style.backgroundColor).toBe('');
});
it('issues #1176', () => {
testComponent.color = 'green';
fixture.detectChanges();
expect(tag.nativeElement.firstElementChild.classList).toContain('ant-tag-green');
testComponent.color = '';
fixture.detectChanges();
expect(tag.nativeElement.firstElementChild.classList).not.toContain('ant-tag-has-color');
testComponent.color = undefined;
fixture.detectChanges();
expect(tag.nativeElement.firstElementChild.classList).not.toContain('ant-tag-has-color');
});
});
describe('prevent tag', () => {
let fixture;
Expand Down

0 comments on commit ba3a323

Please sign in to comment.