Skip to content

Commit 3f1f779

Browse files
committed
fix: Apply primary styling on empty string
Signed-off-by: Akshat Patel <[email protected]>
1 parent a5974c9 commit 3f1f779

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

src/button/button.directive.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import {
22
Directive,
33
HostBinding,
4-
Input,
5-
OnInit
4+
Input
65
} from "@angular/core";
76
import { ButtonSize, ButtonType } from "./button.types";
87

@@ -23,7 +22,7 @@ import { ButtonSize, ButtonType } from "./button.types";
2322
@Directive({
2423
selector: "[cdsButton], [ibmButton]"
2524
})
26-
export class Button implements OnInit {
25+
export class Button {
2726
/**
2827
* @deprecated as of v5 - Use `cdsButton` input property instead
2928
*/
@@ -32,7 +31,7 @@ export class Button implements OnInit {
3231
}
3332
/**
3433
* Sets the button type
35-
* Accepts `ButtonType` or nothing (defaults to empty string in angular 16+)
34+
* Accepts `ButtonType` or nothing (empty string which is equivalent to "primary")
3635
*/
3736
@Input() cdsButton: ButtonType | "" = "primary";
3837
/**
@@ -58,7 +57,8 @@ export class Button implements OnInit {
5857
// a whole lot of HostBindings ... this way we don't have to touch the elementRef directly
5958
@HostBinding("class.cds--btn") baseClass = true;
6059
@HostBinding("class.cds--btn--primary") get primaryButton() {
61-
return this.cdsButton === "primary";
60+
// We need to make sure cdsButton is not an empty string since input name matches selector name.
61+
return this.cdsButton === "primary" || !this.cdsButton;
6262
}
6363
@HostBinding("class.cds--btn--secondary") get secondaryButton() {
6464
return this.cdsButton === "secondary";
@@ -93,14 +93,4 @@ export class Button implements OnInit {
9393
@HostBinding("class.cds--btn--2xl") get twoExtraLargeSize() {
9494
return this.size === "2xl";
9595
}
96-
97-
/**
98-
* We need to make sure cdsButton is not an empty string since
99-
* input name matches selector name.
100-
*/
101-
ngOnInit() {
102-
if (!this.cdsButton) {
103-
this.cdsButton = "primary";
104-
}
105-
}
10696
}

0 commit comments

Comments
 (0)