Skip to content

Commit 0f72031

Browse files
authored
Merge pull request #2864 from Akshat55/issue.2861
fix: merge default notification obj with toast content when set
2 parents 42dd2af + 0c9c2e8 commit 0f72031

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/notification/actionable-notification.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
HostBinding
55
} from "@angular/core";
66

7-
import { of } from "rxjs";
7+
import { isObservable, of } from "rxjs";
88
import { ActionableContent, NotificationVariants } from "./notification-content.interface";
99
import { I18n } from "carbon-components-angular/i18n";
1010
import { NotificationDisplayService } from "./notification-display.service";
@@ -76,7 +76,7 @@ export class ActionableNotification extends BaseNotification {
7676
return this._notificationObj;
7777
}
7878
set notificationObj(obj: ActionableContent) {
79-
if (obj.closeLabel) {
79+
if (obj.closeLabel && !isObservable(obj.closeLabel)) {
8080
obj.closeLabel = of(obj.closeLabel);
8181
}
8282
this._notificationObj = Object.assign({}, this.defaultNotificationObj, obj);

src/notification/notification.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
import { NotificationContent } from "./notification-content.interface";
88
import { I18n } from "carbon-components-angular/i18n";
99
import { NotificationDisplayService } from "./notification-display.service";
10-
import { of } from "rxjs";
10+
import { isObservable, of } from "rxjs";
1111
import { BaseNotification } from "./base-notification.component";
1212

1313
/**
@@ -56,7 +56,7 @@ export class Notification extends BaseNotification {
5656
return this._notificationObj;
5757
}
5858
set notificationObj(obj: NotificationContent) {
59-
if (obj.closeLabel) {
59+
if (obj.closeLabel && !isObservable(obj.closeLabel)) {
6060
obj.closeLabel = of(obj.closeLabel);
6161
}
6262
this._notificationObj = Object.assign({}, this.defaultNotificationObj, obj);

src/notification/toast.component.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
HostBinding
66
} from "@angular/core";
77

8+
import { isObservable, of } from "rxjs";
89
import { ToastContent } from "./notification-content.interface";
910
import { NotificationDisplayService } from "./notification-display.service";
1011
import { I18n } from "carbon-components-angular/i18n";
@@ -36,7 +37,7 @@ import { BaseNotification } from "./base-notification.component";
3637
*ngIf="!isCloseHidden"
3738
class="cds--toast-notification__close-button"
3839
type="button"
39-
[attr.aria-label]="notificationObj.closeLabel"
40+
[attr.aria-label]="notificationObj.closeLabel | async"
4041
(click)="onClose()">
4142
<svg cdsIcon="close" size="16" class="cds--toast-notification__close-icon"></svg>
4243
</button>
@@ -49,7 +50,17 @@ export class Toast extends BaseNotification implements OnInit {
4950
*
5051
* `type` can be one of `"error"`, `"info"`, `"info-square"`, `"warning"`, `"warning-alt"`, or `"success"`
5152
*/
52-
@Input() notificationObj: ToastContent;
53+
@Input() set notificationObj(obj: ToastContent) {
54+
if (obj.closeLabel && !isObservable(obj.closeLabel)) {
55+
obj.closeLabel = of(obj.closeLabel);
56+
}
57+
this._notificationObj = Object.assign({}, this.defaultNotificationObj, obj);
58+
}
59+
60+
get notificationObj(): ToastContent {
61+
return this._notificationObj as ToastContent;
62+
}
63+
5364

5465
@HostBinding("attr.id") toastID = `toast-${Toast.toastCount++}`;
5566
@HostBinding("class.cds--toast-notification") toastClass = true;

0 commit comments

Comments
 (0)