Skip to content

Commit 45d08a1

Browse files
authored
fix(tags): default color (#DS-3705) (#690)
1 parent 21ea414 commit 45d08a1

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

packages/components/core/common-behaviors/color.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export function mixinColor<T extends Constructor<HasElementRef>>(
8383
@Directive({ standalone: true })
8484
export class KbqColorDirective {
8585
readonly elementRef = inject(ElementRef);
86+
private defaultColor: KbqComponentColors | ThemePalette | string;
8687

8788
get colorClassName(): KbqComponentColors | ThemePalette | string {
8889
return `kbq-${this._color}`;
@@ -93,7 +94,9 @@ export class KbqColorDirective {
9394
return this._color;
9495
}
9596

96-
set color(color: KbqComponentColors | ThemePalette | string) {
97+
set color(value: KbqComponentColors | ThemePalette | string) {
98+
const color = value || this.defaultColor;
99+
97100
if (color !== this._color) {
98101
if (this._color) {
99102
this.elementRef.nativeElement.classList.remove(`kbq-${this._color}`);
@@ -112,4 +115,9 @@ export class KbqColorDirective {
112115
constructor() {
113116
this.color = KbqComponentColors.Empty;
114117
}
118+
119+
/** this color will be used as a default value. For example [color]="'' | false | undefined | null". */
120+
setDefaultColor(color: KbqComponentColors | ThemePalette | string) {
121+
this.defaultColor = color;
122+
}
115123
}

packages/components/tags/tag.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ export class KbqTag
220220
super();
221221

222222
this.color = KbqComponentColors.ContrastFade;
223+
this.setDefaultColor(KbqComponentColors.ContrastFade);
223224

224225
this.addHostClassName();
225226

tools/public_api_guard/components/core.api.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1732,13 +1732,14 @@ export class KbqColorDirective {
17321732
constructor();
17331733
// (undocumented)
17341734
get color(): KbqComponentColors | ThemePalette | string;
1735-
set color(color: KbqComponentColors | ThemePalette | string);
1735+
set color(value: KbqComponentColors | ThemePalette | string);
17361736
// (undocumented)
17371737
protected _color: KbqComponentColors | ThemePalette | string;
17381738
// (undocumented)
17391739
get colorClassName(): KbqComponentColors | ThemePalette | string;
17401740
// (undocumented)
17411741
readonly elementRef: ElementRef<any>;
1742+
setDefaultColor(color: KbqComponentColors | ThemePalette | string): void;
17421743
// (undocumented)
17431744
static ɵdir: i0.ɵɵDirectiveDeclaration<KbqColorDirective, never, never, { "color": { "alias": "color"; "required": false; }; }, {}, never, never, true, never>;
17441745
// (undocumented)

0 commit comments

Comments
 (0)