Developer Programs

Learn

Docs

Popup Notification / Toast

Components > User Interaction > Popup Notification / Toast
Use this component to...
Notify the user of an event or occurrence, in a small popup that displays temporarily

Overview

Notifications are used to inform the user of an event occurring or a special status.

Notifications come in four different types:

  • Success: Indicates a successful or positive action.
  • Information: Indicates a neutral informative change or action.
  • Warning: Indicates a warning that might need attention. Warnings typically do not halt forward progress with the current action.
  • Error: Indicates an error or potentially negative action. Errors often halt forward progress with the current action.

Notifications display in one of 3 formats: inline notifications, popup notifications and banner notifications.

This document describes popup notifications.

Popup notifications display in a small popup window in a corner of the screen, then fade away. They do not take up any real estate in the screen, briefly displaying above the screen in a popup.

Popup notifications can be used if the message is less important for the user to see.

You can optionally take action if the user clicks the popup notification.

Popup notifications are sometimes called toast notifications because they often animate upward, similar to a piece of toast popping out of a toaster.
Popup notification on desktop
Popup notification on desktop
Popup notification on mobile
Popup notification on mobile

Development

Web component development

Component reference

rui-popup-notification
rui-popup-notification
Module: rui-notifications - Package: @jkhy/responsive-ui-wc

Notification message that displays in a popup

NameTypeDefaultDescription
typestring'information'Specifies the type of popup notification styling to display. One of “information”, “success”, “error”, or “warning”.
textstring''The text to display in the popup notification.
showNotificationbooleanfalseThis is a boolean trigger property. Bind this property to a backing boolean value in your controller, then set the backing value to true whenever you want to display the popup notification.
rui-popup-notification-show-notification-changeeventEvent fired when the showNotification property value resets within the component. You must reset the backing boolean value in your controller to which the showNotification property is bound when this event fires.
autoDismissbooleantrueBy default, popup notifications automatically dismiss themselves after displaying for a few seconds. Bind this property to a value of false if you want the popup notification to stay displayed until the user manually clicks it.
rui-clickeventEvent fired when the user clicks the popup notification. The popup notification closes when the user clicks it.
closeButtonTextstring''

If you want to display a special button within the popup notification, use this property to specify the text for this button. The rui-close-button-click event fires when the user presses this close button, as opposed to the rui-click event that fires when the user clicks anywhere else in the popup notification.

This can be useful if you want to provide the user with an extra option, in addition to the ability to clicking the notification to close it.

For example, you might want to include an “UNDO” button within the popup notification. If the user presses the “UNDO” button, the rui-close-button-click event fires, at which point your app could undo the previous action. If the user clicks anywhere outside the “UNDO” button, the rui-click event fires, at which point your app would not undo the previous action.

rui-close-button-clickeventEvent fired when the user clicks the close button within the popup notification.

Implementation

Use rui-popup-notification to display a popup notification.

  • Specify the notification text with the text property.
  • Specify the type of notification to display with the type property.
  • Bind the showNotification property to a boolean value in your TypeScript, then set the backing value to true whenever you want to display the popup notification.
  • Optionally bind autoDismiss to false to require the user to click to dismiss the notification.
  • Optionally handle the rui-click event if you want to perform an action when the user clicks the notification.
  • Optionally define a separate button within the popup notification by specifying text for the button using the closeButtonText property and handling the rui-close-button-click event.

Begin by importing the rui-notifications module into your application.

Import the module
// import into app.module
import '@jkhy/responsive-ui-wc/components/rui-notifications/rui-notifications-imports';

We start by defining a showSuccessPopupNotification boolean property in our TypeScript, initializing that to a value of false. This property will control when the popup displays.

Property that controls the popup notification display
public showSuccessPopupNotification: boolean = false;

Next we add the rui-popup-notification to the HTML with a type of success and an appropriate message to display. We bind the showNotification property to the backing showSuccessPopupNotification boolean property in the TypeScript. We handle the rui-popup-notification-show-notification-change event by resetting the showSuccessPopupNotification backing value.

Popup notification HTML
<rui-popup-notification type="success" text="This is a Success popup notification"
    [showNotification]="showSuccessPopupNotification"
    (rui-popup-notification-show-notification-change)="showButtonPopupNotification = $event.detail"
    (rui-click)="popupNotificationClicked('Success')">
</rui-popup-notification>

In this example, we use a button to trigger the display of the popup notification. This button’s click event handler simply sets the showSuccessPopupNotification boolean property to a value of true when pressed. This displays the popup notification.

Trigger button HTML
<rui-button text="Show Success popup notification" (rui-click)="showSuccessPopupNotification = true">
</rui-button>

We defined popupNotificationClicked() as the event handler for the popup notification’s jhaNotificationClick event. In this example we’re just logging the console message whenever the user clicks the popup notification.

Handling popup notification click
public popupNotificationClicked(notificationType: string) {
    console.log(notificationType + ' notification was clicked');
}

Angular wrapper development

Wrapper reference

jha-popup-notification
jha-popup-notification
Module: JhaNotificationsModule - Package: @jkhy/responsive-ui-angular

Notification message that displays in a popup

NameTypeDefaultDescription
jhaTypestring'information'Specifies the type of popup notification styling to display. One of “Information”, “Success”, “Error”, or “Warning”. The default is “Information”.
jhaTextstring''The text to display in the popup notification.
jhaShowNotificationbooleanfalseThis is a boolean trigger property. Bind this property to a backing boolean value in your controller, then set the backing value to true whenever you want to display the popup notification.
jhaAutoDismissbooleantrueBy default, popup notifications automatically dismiss themselves after displaying for a few seconds. Bind this property to a value of false if you want the popup notification to stay displayed until the user manually clicks it.
jhaNotificationClickeventEvent fired when the user clicks the popup notification. The popup notification closes when the user clicks it.

Implementation

Use jha-popup-notification to display a popup notification.

  • Specify the notification text with the jhaText property.
  • Specify the type of notification to display with the jhaType property.
  • Bind the jhaShowNotification property to a boolean value in your TypeScript, then set the backing value to true whenever you want to display the popup notification.
  • Optionally bind jhaAutoDismiss to false to require the user to click to dismiss the notification.
  • Optionally handle the jhaNotificationClick event if you want to perform an action when the user clicks the notification.

Include noty in package.json, where x.y.z is the currently supported version number for this framework specified here. Use npm install to install this framework.

Package dependencies
"dependencies": {
    ...
    "noty": "x.y.z",
    ...
},

Once the package has been installed, add it to your scripts bundle in the angular.json file.

Script bundle
"scripts": [
    ...
    "node_modules/noty/js/noty/packaged/jquery.noty.packaged.min.js"
]

Begin by importing the JhaNotificationsModule module into your application.

Import the module
// import into app.module
import { JhaNotificationsModule } from '@jkhy/responsive-ui-angular/jha-notifications';

@NgModule({
    imports: [
        ...
        JhaNotificationsModule,
        ...
    ]
})

export class AppModule(){}

We start by defining a showSuccessPopupNotification boolean property in our TypeScript, initializing that to a value of false. This property will control when the popup displays.

Property that controls the popup notification display
public showSuccessPopupNotification: boolean = false;

Next we add the jha-popup-notification to the HTML with a type of success and an appropriate message to display. We bind the showNotification property to the backing showSuccessPopupNotification boolean property in the TypeScript. We handle the jha-popup-notification-show-notification-change event by resetting the showSuccessPopupNotification backing value.

Popup notification HTML
<jha-popup-notification jhaType="Success" jhaText="This is a Success popup notification"
    [(jhaShowNotification)]="showSuccessPopupNotification" (jhaNotificationClick)="popupNotificationClicked('Success')">
</jha-popup-notification>

In this example, we use a button to trigger the display of the popup notification. This button’s click event handler simply sets the showSuccessPopupNotification boolean property to a value of true when pressed. This displays the popup notification.

Trigger button HTML
<jha-button jhaText="Show Success popup notification" class="popup-button" (jhaClick)="showSuccessPopupNotification = true">
</jha-button>

We defined popupNotificationClicked() as the event handler for the popup notification’s jhaNotificationClick event. In this example we’re just logging the console message whenever the user clicks the popup notification.

Handling popup notification click
public popupNotificationClicked(notificationType: string) {
    console.log(notificationType + ' notification was clicked');
}

In most scenarios you’ll use the jha-popup-notification element described above. But in some cases it may make more sense to display popup notifications programmatically without using a visual element. For these cases, you can use the JhaNotificationService service.

To do this, first include the JhaNotificationService service.

Call jhaNotificationService.DisplayPopupNotification(notificationText, notificationType) to display a popup notification.

  • notificationText is the string message to display.
  • notificationType is one of Information, Success, Warning, or Error, all values in the JhaNotificationTypes enum.

Call jhaNotificationService.DisplayPopupNotificationClick(notificationText, notificationType, clickCallback, notificationAutoDismiss) to display a popup notification and do something if the user clicks the notification.

  • notificationText is the string message to display.
  • notificationType is one of Information, Success, Warning, or Error, all values in the JhaNotificationTypes enum.
  • clickCallback is JavaScript to execute when the user clicks the notification.
  • notificationAutoDismiss (optional) allows you to require the user to click the notification to dismiss it, when set to false. The popup notification hides when the user clicks it.
Handling popup notification click
// import into your component
import { JhaNotificationService } from '@jkhy/responsive-ui-angular/jha-notifications';
import { JhaNotificationTypes } from '@jkhy/responsive-ui-angular/jha-notifications';

export class PopupNotificationComponent {

    constructor(private jhaNotificationService: JhaNotificationService) {}

    createNotification() {
        this.jhaNotificationService.DisplayPopupNotificationClick('Notification created',
            JhaNotificationTypes.Success, function () { console.log('Notification clicked') });
    }

}

Design

Figma design

Figma design info
You can find this component in the Components - Notifications page in the Figma UI Kit.
Dev ComponentDesign Component Name
Popup notification

RUI / Notifications / Popup

Available values for the Type property:

  • Information
  • Success
  • Warning
  • Error

Popup notifications (a.k.a. “toast” notifications) display at the bottom-right of the screen for a few seconds, then disappear.

Do not change the size of a popup notification as these are fixed in the dev components.


Adobe XD design

Adobe XD design info
You can find this component in these artboards in the Adobe XD design samples:
  • Sample App - Notifications
Dev ComponentDesign Component Name
Popup notification - SuccessJHA / Notifications / Popup / Success
Popup notification - InformationJHA / Notifications / Popup / Information
Popup notification - WarningJHA / Notifications / Popup / Warning
Popup notification - ErrorJHA / Notifications / Popup / Error

Popup notifications (a.k.a. “toast” notifications) display at the bottom-right of the screen for a few seconds, then disappear.

Do not change the size of a popup notification as these are fixed in the dev components.


Support options
Have questions on this topic?
Join the Responsive UI team in Microsoft Teams to connect with the community.
See something in this page that needs to change?
Send us feedback on this page.
Last updated Mon May 1 2023