Skip to content

Commit

Permalink
Merge pull request #2864 from Akshat55/issue.2861
Browse files Browse the repository at this point in the history
fix: merge default notification obj with toast content when set
  • Loading branch information
zvonimirfras authored Apr 25, 2024
2 parents 42dd2af + 0c9c2e8 commit 0f72031
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/notification/actionable-notification.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
HostBinding
} from "@angular/core";

import { of } from "rxjs";
import { isObservable, of } from "rxjs";
import { ActionableContent, NotificationVariants } from "./notification-content.interface";
import { I18n } from "carbon-components-angular/i18n";
import { NotificationDisplayService } from "./notification-display.service";
Expand Down Expand Up @@ -76,7 +76,7 @@ export class ActionableNotification extends BaseNotification {
return this._notificationObj;
}
set notificationObj(obj: ActionableContent) {
if (obj.closeLabel) {
if (obj.closeLabel && !isObservable(obj.closeLabel)) {
obj.closeLabel = of(obj.closeLabel);
}
this._notificationObj = Object.assign({}, this.defaultNotificationObj, obj);
Expand Down
4 changes: 2 additions & 2 deletions src/notification/notification.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { NotificationContent } from "./notification-content.interface";
import { I18n } from "carbon-components-angular/i18n";
import { NotificationDisplayService } from "./notification-display.service";
import { of } from "rxjs";
import { isObservable, of } from "rxjs";
import { BaseNotification } from "./base-notification.component";

/**
Expand Down Expand Up @@ -56,7 +56,7 @@ export class Notification extends BaseNotification {
return this._notificationObj;
}
set notificationObj(obj: NotificationContent) {
if (obj.closeLabel) {
if (obj.closeLabel && !isObservable(obj.closeLabel)) {
obj.closeLabel = of(obj.closeLabel);
}
this._notificationObj = Object.assign({}, this.defaultNotificationObj, obj);
Expand Down
15 changes: 13 additions & 2 deletions src/notification/toast.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
HostBinding
} from "@angular/core";

import { isObservable, of } from "rxjs";
import { ToastContent } from "./notification-content.interface";
import { NotificationDisplayService } from "./notification-display.service";
import { I18n } from "carbon-components-angular/i18n";
Expand Down Expand Up @@ -36,7 +37,7 @@ import { BaseNotification } from "./base-notification.component";
*ngIf="!isCloseHidden"
class="cds--toast-notification__close-button"
type="button"
[attr.aria-label]="notificationObj.closeLabel"
[attr.aria-label]="notificationObj.closeLabel | async"
(click)="onClose()">
<svg cdsIcon="close" size="16" class="cds--toast-notification__close-icon"></svg>
</button>
Expand All @@ -49,7 +50,17 @@ export class Toast extends BaseNotification implements OnInit {
*
* `type` can be one of `"error"`, `"info"`, `"info-square"`, `"warning"`, `"warning-alt"`, or `"success"`
*/
@Input() notificationObj: ToastContent;
@Input() set notificationObj(obj: ToastContent) {
if (obj.closeLabel && !isObservable(obj.closeLabel)) {
obj.closeLabel = of(obj.closeLabel);
}
this._notificationObj = Object.assign({}, this.defaultNotificationObj, obj);
}

get notificationObj(): ToastContent {
return this._notificationObj as ToastContent;
}


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

0 comments on commit 0f72031

Please sign in to comment.