Skip to content

Commit da81ab2

Browse files
committed
fix: Apply white theme on empty string input
Signed-off-by: Akshat Patel <[email protected]>
1 parent 3f1f779 commit da81ab2

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

src/theme/theme.directive.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
Directive,
55
HostBinding,
66
Input,
7-
OnInit,
87
QueryList
98
} from "@angular/core";
109
import { LayerDirective } from "carbon-components-angular/layer";
@@ -20,7 +19,7 @@ export type ThemeType = "white" | "g10" | "g90" | "g100";
2019
selector: "[cdsTheme], [ibmTheme]",
2120
exportAs: "theme"
2221
})
23-
export class ThemeDirective implements OnInit, AfterContentChecked {
22+
export class ThemeDirective implements AfterContentChecked {
2423
/**
2524
* @deprecated as of v5 - Use `cdsTheme` input property instead
2625
*/
@@ -30,7 +29,7 @@ export class ThemeDirective implements OnInit, AfterContentChecked {
3029

3130
/**
3231
* Sets the theme for the content
33-
* Accepts `ThemeType` or nothing (defaults to empty string in angular 16+)
32+
* Accepts `ThemeType` or nothing (empty string which is equivalent to "white")
3433
*/
3534
@Input() cdsTheme: ThemeType | "" = "white";
3635

@@ -41,7 +40,7 @@ export class ThemeDirective implements OnInit, AfterContentChecked {
4140
* overwrite user added classes
4241
*/
4342
@HostBinding("class.cds--white") get whiteThemeClass() {
44-
return this.cdsTheme === "white";
43+
return this.cdsTheme === "white" || !this.cdsTheme;
4544
}
4645

4746
@HostBinding("class.cds--g10") get g10ThemeClass() {
@@ -69,14 +68,4 @@ export class ThemeDirective implements OnInit, AfterContentChecked {
6968
}
7069
});
7170
}
72-
73-
/**
74-
* We need to make sure cdsTheme is not an empty string because
75-
* input name matches selector name.
76-
*/
77-
ngOnInit(): void {
78-
if (!this.cdsTheme) {
79-
this.cdsTheme = "white";
80-
}
81-
}
8271
}

0 commit comments

Comments
 (0)