Notifications
Notifications are short messages that communicate information to the user. They appear inline to body text or as toast messages.
Notifications are short messages that communicate information to the user. They appear inline to body text or as toast messages.
Use the codes below to add this component to your project. Download the latest version of the library to easily implement our full range of components.
Execute the following command to install this component.
npm i [NPM-PLACE-HOLDER]/ds-notification npm i [NPM-PLACE-HOLDER]/ds-toast-notification
Import the following into your app.module.ts file.
import { DsNotificationModule } from 'ds-notification'; import { DsToastNotificationModule } from 'ds-toast-notification';
import { DsNotificationService } from 'ds-notification'; import { DsToastNotificationService } from 'ds-toast-notification';
<cpc-ds-notification [fade]="true"></cpc-ds-notification> <button (click)="alertService.info('Information notifications provide non-essential, but helpful information. \<a href class=by-keyboard>View Information</a>', 'The item details have been deleted. \<a href class=by-keyboard>Link</a>', options)">Info</button>
<cpc-ds-notification [fade]="true"></cpc-ds-notification> <button (click)="alertService.success('Success notifications indicate that a user has successfully completed an action.', 'Delivery preference is saved.', options)">Success</button>
<cpc-ds-notification [fade]="true"></cpc-ds-notification> <button (click)="alertService.warn('Warning notifications provide essential information to prevent users from making an error.', 'The option to make changes is no longer available.', options)">Warning</button>
<cpc-ds-notification [fade]="true"></cpc-ds-notification> <button (click)="alertService.warn('Warning notifications provide essential information to prevent users from making an error.', 'The option to make changes is no longer available.', options)">Warning</button> <button (click)="alertService.error('<p>Error notifications tell users what’s required to successfully complete the action they are trying to complete.</p><div class=inline-links><p><a href class=by-keyboard>View Information</a></p><p><a href class=by-keyboard>View Information</a></p><p><a href class=by-keyboard>View Information</a></p></div>', '<p>Error notifications tell users what’s required to successfully complete the action they are trying to complete.</p><div class=inline-links><p><a href class=by-keyboard>View Information</a></p><p><a href class=by-keyboard>View Information</a></p><p><a href class=by-keyboard>View Information</a></p></div>', options)">Error</button>
<cpc-ds-toast-notification class="toastContainer" [fade]="true"></cpc-ds-toast-notification> <button (click)="toastService.success('Success notifications indicate that a user has successfully completed an action.', 'Success notifications <a href class=by-keyboard>View</a>', optionsToast)">Success</button>
<cpc-ds-toast-notification class="toastContainer" [fade]="true"></cpc-ds-toast-notification> <button (click)="toastService.error('Error notifications tell users what’s required to successfully complete the action they are trying to complete.</p><div class=inline-links><p><a href class=by-keyboard>View Information</a></p><p><a href class=by-keyboard>View Information</a></p><p><a href class=by-keyboard>View Information</a></div>', 'Error notifications tell users what’s required to successfully complete the action they are trying to complete. <a href class=by-keyboard>View Information</a>', optionsToast)">Error</button>
Name | Type | Default | Description |
---|---|---|---|
id | string |
Button id. |
|
class | string | primary-button by-keyboard |
There are two types of buttons: primary-button and secondary-button |
body | string |
Button text : for eg: body='button text' |
|
(click) | method |
Call the method : |
|
alertService | method |
Call the method : Alert service has 4 methods: info success warn error Each method contains 2 parameters: Notification message Options Options are: showCloseButton autoClose keepAfterRouteChange infoAriaLabel successAriaLabel warningAriaLabel errorAriaLabel |
|
showCloseButton | boolean | Show/Hide close button (except Error notification). for eg:-
options = { showCloseButton: true; autoClose: false, keepAfterRouteChange: false, infoAriaLabel: 'Note', successAriaLabel: 'Success', warningAriaLabel: 'Caution', errorAriaLabel: 'Error', }; |
|
autoClose | boolean | Auto-close the notification. Error notification wont auto close for eg:-
options = { showCloseButton: true; autoClose: false, keepAfterRouteChange: false, infoAriaLabel: 'Note', successAriaLabel: 'Success', warningAriaLabel: 'Caution', errorAriaLabel: 'Error', }; |
|
keepAfterRouteChange | boolean | Keep the notification showing even if route changes. for eg:-
options = { showCloseButton: true; autoClose: false, keepAfterRouteChange: false, infoAriaLabel: 'Note', successAriaLabel: 'Success', warningAriaLabel: 'Caution', errorAriaLabel: 'Error', }; |
|
infoAriaLabel | boolean | Aria label text for info notification for eg:-
options = { showCloseButton: true; autoClose: false, keepAfterRouteChange: false, infoAriaLabel: 'Note', successAriaLabel: 'Success', warningAriaLabel: 'Caution', errorAriaLabel: 'Error', }; |
|
successAriaLabel | boolean | Aria label text for success notification for eg:-
options = { showCloseButton: true; autoClose: false, keepAfterRouteChange: false, infoAriaLabel: 'Note', successAriaLabel: 'Success', warningAriaLabel: 'Caution', errorAriaLabel: 'Error', }; |
|
warningAriaLabel | boolean | Aria label text for warning notification for eg:-
options = { showCloseButton: true; autoClose: false, keepAfterRouteChange: false, infoAriaLabel: 'Note', successAriaLabel: 'Success', warningAriaLabel: 'Caution', errorAriaLabel: 'Error', }; |
|
errorAriaLabel | boolean | Aria label text for error notification for eg:-
options = { showCloseButton: true; autoClose: false, keepAfterRouteChange: false, infoAriaLabel: 'Note', successAriaLabel: 'Success', warningAriaLabel: 'Caution', errorAriaLabel: 'Error', }; |
Import the following into your theme or page.
Import the following into your theme or page.
<script src="[JS-PLACE-HOLDER]"></script>
Toast Notifications
<button onclick="createNotification(cssType = 'toast', toastType = 'success', toastIconAria = 'Success:', desktopMessage = 'Delivery preference is saved.', mobileMessage = 'Delivery preference is saved.', closeButton = true, autoClose = true)">Success</button>
<button onclick="createNotification(cssType = 'toast', toastType = 'error', toastIconAria = 'Error:', desktopMessage = 'Error notifications tell users what’s required to successfully complete the action they are trying to complete.', mobileMessage = 'Error notifications tell users what’s required to successfully complete the action they are trying to complete.', closeButton = true, autoClose = false)">Error</button>
<button onclick="createNotification(cssType = 'notification', toastType = 'info', toastIconAria = 'Note:', desktopMessage = 'Information notifications provide non-essential, but helpful information. <a href=\'#\' class=\'by-keyboard\'>View more</a>', mobileMessage = 'The item details have been deleted.', closeButton = true, autoClose = false)">Info</button>
<button onclick="createNotification(cssType = 'notification', toastType = 'success', toastIconAria = 'Success:', desktopMessage = 'Success notifications indicate that a user has successfully completed an action.', mobileMessage = 'Delivery preference is saved.', closeButton = true, autoClose = false)">Success</button>
<button onclick="createNotification(cssType = 'notification', toastType = 'warning', toastIconAria = 'Caution:', desktopMessage = 'Warning notifications provide essential information to prevent users from making an error.', mobileMessage = 'The option to make changes is no longer available.', closeButton = true, autoClose = false)">Warning</button>
<button onclick="createNotification(cssType = 'notification', toastType = 'error', toastIconAria = 'Error:', desktopMessage = 'Error notifications tell users what’s required to successfully complete the action they are trying to complete.<div class=\'inline-links\'><p><a href=\'#\' class=\'by-keyboard\'>View more</a></p><p><a href=\'#\' class=\'by-keyboard\'>View more</a></p><p><a href=\'#\' class=\'by-keyboard\'>View more</a></p></div>', mobileMessage = 'Error notifications tell users what’s required to successfully complete the action they are trying to complete.<div class=\'inline-links\'><p><a href=\'#\' class=\'by-keyboard\'>View more</a></p><p><a href=\'#\' class=\'by-keyboard\'>View more</a></p><p><a href=\'#\' class=\'by-keyboard\'>View more</a></p></div>', closeButton = false, autoClose = false)">Error</button>
<button onclick="createNotification(cssType = 'notification', toastType = 'info', toastIconAria = 'Note:', desktopMessage = 'Information notifications provide non-essential, but helpful information. <a href=\'#\' class=\'by-keyboard\'>View more</a>', mobileMessage = 'The item details have been deleted.', closeButton = false, autoClose = false)">Info</button>
<button onclick="createNotification(cssType = 'notification', toastType = 'success', toastIconAria = 'Success:', desktopMessage = 'Success notifications indicate that a user has successfully completed an action.', mobileMessage = 'Delivery preference is saved.', closeButton = false, autoClose = false)">Success</button>
<button onclick="createNotification(cssType = 'notification', toastType = 'warning', toastIconAria = 'Caution:', desktopMessage = 'Warning notifications provide essential information to prevent users from making an error.', mobileMessage = 'The option to make changes is no longer available.', closeButton = false, autoClose = false)">Warning</button>
<button onclick="createNotification(cssType = 'notification', toastType = 'error', toastIconAria = 'Error:', desktopMessage = 'Error notifications tell users what’s required to successfully complete the action they are trying to complete.</p><div class=\'inline-links\'><p><a href=\'#\' class=\'by-keyboard\'>View more</a></p><p><a href=\'#\' class=\'by-keyboard\'>View more</a></p><p><a href=\'#\' class=\'by-keyboard\'>View more</a></p></div>', mobileMessage = 'Error notifications tell users what’s required to successfully complete the action they are trying to complete.</p><div class=\'inline-links\'><p><a href=\'#\' class=\'by-keyboard\'>View more</a></p><p><a href=\'#\' class=\'by-keyboard\'>View more</a></p><p><a href=\'#\' class=\'by-keyboard\'>View more</a></p></div>', closeButton = false, autoClose = false)">Error</button>
Notifications let users know about errors, successes, alerts, and contextual information with minimal distraction, while keeping them on the page.
Notifications can have the following states:Write notifications using simple, clear language. They should contain content communicating information, a success message, an alert, or an error.
Guidelines | Examples | |
---|---|---|
Recommended length | Up to 20 words | You’ve successfully verified your identity at Canada Post. |
Line wrap | Minimize | Services will be unavailable from July 14 at 9 p.m. to July 15 at 9 a.m. ET. |
Phrasing | Complete sentences | You’ve already signed up for FlexDelivery, but haven’t verified your identity. You must verify your identity to use FlexDelivery. |
Case | Sentence case with period | You've successfully added a credit card to your profile. |
Explain the situation from the user’s point of view. Focus on the issue and not why users are seeing the notification.
Error messages should appear only when needed. They need to be helpful, relevant, free of jargon and friendly.
The dismiss icon tells users to close the notification. Write alt text for the X symbol.
Notifications contain an appropriate icon that relates to the context. Apply alt text that describes the function of the notification.
Note that this component may require additional styling.
Notifications have no focus halo of their own. Interactive controls inside the notification body have a prominent focus outline when they're focused or hovered.
The notification itself isn't interactive. Interactive elements inside the notification should be present in the page tab order.
Links or buttons inside of the notification or toast body should follow their respective keyboard interactions.
Make sure that the notification/toast is immediately next to the triggering element in the DOM order so that a keyboard or screen reader user is easily able to interact with it.
Notifications and toasts should have the following ARIA properties:
Users can choose to turn off a notification’s animation on an operating system or browser level. We respect the user's choice and don't use animations for notifications when users have opted to disable them.
The CSS property prefers-reduced-motion can tell us if the user has opted to turn off animations when its value is “reduce”. In such cases, fly-in and fly-out animations should be disabled.
When testing notifications, the tester must ensure: