Skip to content

Commit 47d44ba

Browse files
authored
fix(module:badge): hex nzColor should work (#9517)
1 parent 0e095a1 commit 47d44ba

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

‎components/badge/badge.component.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ const NZ_CONFIG_MODULE_NAME: NzConfigKey = 'badge';
5555
[nzOffset]="nzOffset"
5656
[nzSize]="nzSize"
5757
[nzTitle]="nzTitle"
58-
[nzStyle]="nzStyle"
58+
[nzStyle]="mergedStyle"
5959
[nzDot]="nzDot"
6060
[nzCount]="nzCount"
6161
[nzOverflowCount]="nzOverflowCount"
62-
[disableAnimation]="!!(nzStandalone || nzStatus || nzColor || noAnimation?.nzNoAnimation)"
62+
[disableAnimation]="!!(nzStandalone || nzStatus || presetColor || noAnimation?.nzNoAnimation)"
6363
[noAnimation]="!!noAnimation?.nzNoAnimation"
6464
/>
6565
}

‎components/badge/badge.spec.ts‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@
33
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
44
*/
55

6-
import { BidiModule, Dir, Direction } from '@angular/cdk/bidi';
7-
import { Component, DebugElement, ViewChild } from '@angular/core';
6+
import { BidiModule, Direction } from '@angular/cdk/bidi';
7+
import { Component, DebugElement } from '@angular/core';
88
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
99
import { By } from '@angular/platform-browser';
1010
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
1111

12-
import { badgePresetColors } from 'ng-zorro-antd/badge/preset-colors';
13-
import { NzRibbonComponent } from 'ng-zorro-antd/badge/ribbon.component';
1412
import { NzNoAnimationDirective } from 'ng-zorro-antd/core/no-animation';
1513
import { NgStyleInterface, NzSizeDSType } from 'ng-zorro-antd/core/types';
1614

1715
import { NzBadgeComponent } from './badge.component';
1816
import { NzBadgeModule } from './badge.module';
17+
import { badgePresetColors } from './preset-colors';
18+
import { NzRibbonComponent } from './ribbon.component';
19+
import { NzBadgeStatusType } from './types';
1920

2021
describe('nz-badge', () => {
2122
beforeEach(() => {
@@ -242,8 +243,22 @@ describe('nz-badge', () => {
242243
expect(badgeElement.nativeElement.querySelector('.ant-badge-status-text')).toBeNull();
243244
}));
244245

246+
it('should hex nzColor work', () => {
247+
testComponent.count = 0;
248+
testComponent.color = '#f5222d';
249+
fixture.detectChanges();
250+
expect(badgeElement.nativeElement.querySelector('.ant-badge-status-dot').style.backgroundColor).toBe(
251+
'rgb(245, 34, 45)'
252+
);
253+
254+
testComponent.count = 5;
255+
fixture.detectChanges();
256+
expect(badgeElement.nativeElement.querySelector('nz-badge-sup').style.backgroundColor).toBe('rgb(245, 34, 45)');
257+
});
258+
245259
it('should nzStyle work even if nzColor is not provided', () => {
246260
testComponent.color = undefined;
261+
testComponent.status = 'success'; // must set nzStatus to make sure status dot is rendered
247262
testComponent.style = { backgroundColor: '#52c41a' };
248263
fixture.detectChanges();
249264
expect(badgeElement.nativeElement.querySelector('nz-badge-sup').style.backgroundColor).toBe('rgb(82, 196, 26)');
@@ -345,7 +360,7 @@ export class NzTestBadgeBasicComponent {
345360
standalone = false;
346361
overflow = 20;
347362
showZero = false;
348-
status!: string;
363+
status!: NzBadgeStatusType | string;
349364
style!: NgStyleInterface;
350365
text!: string;
351366
title?: string | null;
@@ -364,7 +379,6 @@ export class NzTestBadgeBasicComponent {
364379
`
365380
})
366381
export class NzTestBadgeRtlComponent {
367-
@ViewChild(Dir) dir!: Dir;
368382
direction: Direction = 'rtl';
369383
count = 5;
370384
}

0 commit comments

Comments
 (0)