Toast
The toast component is like an alert box that is only shown for a couple of seconds when something happens.
Selector
smart-toast
Properties
true
; otherwise, the toast will remain visible until manually closed.true
, any values specified for position and appendTo will be ignored, and the toast will always appear centered in a modal overlay.Events
Methods
Properties
animation"none" | "simple" | "advanced"
Sets or retrieves the animation mode for the component. When this property is set to 'none', all animations are disabled. Otherwise, specifying a valid animation mode enables corresponding transition effects.
Allowed Values
- "none" - animation is disabled
- "simple" - ripple animation is disabled
- "advanced" - all animations are enabled
Default value
"advanced"Example
Set the animation property.
<smart-toast animation='none'></smart-toast>
Set the animation property by using the HTML Element's instance.
const toast = document.querySelector('smart-toast');
toast.animation = 'simple';
Get the animation property.
const toast = document.querySelector('smart-toast');
let animation = toast.animation;
appendTostring
Defines the container element in which new toast notifications will appear. The value can be either an HTMLElement directly, or a string representing the id of a DOM element. This property determines where toast items are rendered in the DOM.
Note: When used together with the modal and position properties, container takes precedence over position but has lower priority than modal. This means that if modal is enabled, it overrides container; if not, the specified container is used instead of the position property.
Default value
"null"Example
Set the appendTo property.
<smart-toast append-to='container'></smart-toast>
Set the appendTo property by using the HTML Element's instance.
const toast = document.querySelector('smart-toast');
toast.appendTo = 'newContainer';
Get the appendTo property.
const toast = document.querySelector('smart-toast');
let appendTo = toast.appendTo;
autoCloseboolean
Determines whether the toast notification will automatically close after the duration specified by the autoCloseDelay property. If enabled, the toast will dismiss itself once the set time has elapsed; otherwise, it will remain visible until manually closed by the user.
Default value
falseExample
Set the autoClose property.
<smart-toast auto-close></smart-toast>
Set the autoClose property by using the HTML Element's instance.
const toast = document.querySelector('smart-toast');
toast.autoClose = false;
Get the autoClose property.
const toast = document.querySelector('smart-toast');
let autoClose = toast.autoClose;
autoCloseDelaynumber
Specifies or retrieves the time interval (in milliseconds) after which the toast notification will automatically dismiss itself. This property is effective only when the autoClose property is set to true
; otherwise, the toast will remain visible until manually closed.
Default value
3000Example
Set the autoCloseDelay property.
<smart-toast auto-close-delay='4000'></smart-toast>
Set the autoCloseDelay property by using the HTML Element's instance.
const toast = document.querySelector('smart-toast');
toast.autoCloseDelay = 5000;
Get the autoCloseDelay property.
const toast = document.querySelector('smart-toast');
let autoCloseDelay = toast.autoCloseDelay;
autoOpenboolean
Determines whether the toast notification should automatically appear as soon as the widget is initialized, without requiring any user interaction or additional trigger.
Default value
falseExample
Set the autoOpen property.
<smart-toast auto-open></smart-toast>
Set the autoOpen property by using the HTML Element's instance.
const toast = document.querySelector('smart-toast');
toast.autoOpen = false;
Get the autoOpen property.
const toast = document.querySelector('smart-toast');
let autoOpen = toast.autoOpen;
disabledboolean
When the disabled property is set to true, all user interactions with toast items—such as clicking, hovering, or dismissing—will be prevented. The toast items will appear inactive and will not respond to any user actions until disabled is set to false.
Default value
falseExample
Set the disabled property.
<smart-toast disabled></smart-toast>
Set the disabled property by using the HTML Element's instance.
const toast = document.querySelector('smart-toast');
toast.disabled = false;
Get the disabled property.
const toast = document.querySelector('smart-toast');
let disabled = toast.disabled;
iconClassstring
Specifies a custom CSS class name or multiple class names to override the default icon styling. To apply multiple classes, separate each class name with a space (e.g., "fa fa-user"). This property is particularly useful when integrating icons from third-party icon libraries like Bootstrap Icons, Font Awesome, or Material Icons, allowing you to fully control the icon's appearance by leveraging external style definitions.
Default value
"null"Example
Set the iconClass property.
<smart-toast icon-class='material-icons'></smart-toast>
Set the iconClass property by using the HTML Element's instance.
const toast = document.querySelector('smart-toast');
toast.iconClass = 'glyphicon glyphicon-cloud';
Get the iconClass property.
const toast = document.querySelector('smart-toast');
let iconClass = toast.iconClass;
itemClassstring
Allows you to add one or more custom CSS classes to Toast items by specifying class names separated with spaces. This enables you to style individual Toasts using predefined classes from third-party CSS frameworks (such as Bootstrap), or your own custom styles, for greater flexibility and consistency in appearance.
Default value
"null"Example
Set the itemClass property.
<smart-toast item-class='mat-elevation-z6'></smart-toast>
Set the itemClass property by using the HTML Element's instance.
const toast = document.querySelector('smart-toast');
toast.itemClass = 'custom-toast red';
Get the itemClass property.
const toast = document.querySelector('smart-toast');
let itemClass = toast.itemClass;
itemTemplatestring
Defines a custom template for rendering each item, allowing you to control the appearance and structure of items displayed in the list or component. This enables the use of personalized HTML, styling, and dynamic content for each item, rather than relying on the default rendering format.
Default value
"null"Example
Set the itemTemplate property.
<smart-toast item-template='templateId1'></smart-toast>
Set the itemTemplate property by using the HTML Element's instance.
const toast = document.querySelector('smart-toast');
toast.itemTemplate = 'templateId2';
Get the itemTemplate property.
const toast = document.querySelector('smart-toast');
let itemTemplate = toast.itemTemplate;
unlockKeystring
Defines or retrieves the unlockKey, a unique value required to activate or gain access to the product’s features or content.
Default value
""Example
Set the unlockKey property.
<smart-toast unlock-key=''></smart-toast>
Set the unlockKey property by using the HTML Element's instance.
const toast = document.querySelector('smart-toast');
toast.unlockKey = '1111-2222-3333-4444-5555';
Get the unlockKey property.
const toast = document.querySelector('smart-toast');
let unlockKey = toast.unlockKey;
localestring
Specifies or retrieves the current language setting for localization purposes. This property determines which set of translations from the messages object is used, ensuring that the appropriate language-specific content is displayed or accessed.
Default value
"en"Example
Set the locale property.
<smart-toast locale='de'></smart-toast>
Set the locale property by using the HTML Element's instance.
const toast = document.querySelector('smart-toast');
toast.locale = 'fr';
Get the locale property.
const toast = document.querySelector('smart-toast');
let locale = toast.locale;
localizeFormatFunctionfunction | null
Callback function used by the localization module to handle language-specific operations, such as loading translation files, switching languages, or updating localized content dynamically within the application.
Example
Set the localizeFormatFunction property.
<smart-toast localize-format-function='function(){return '...'}'></smart-toast>
Set the localizeFormatFunction property by using the HTML Element's instance.
const toast = document.querySelector('smart-toast');
toast.localizeFormatFunction = function(){return '...'};
Get the localizeFormatFunction property.
const toast = document.querySelector('smart-toast');
let localizeFormatFunction = toast.localizeFormatFunction;
messagesobject
Defines or retrieves an object containing customizable text strings used throughout the widget’s user interface, enabling localization and internationalization of displayed messages, labels, and prompts. Typically used alongside the locale property to support multiple languages and regional formats. This property allows developers to override default strings with translations or custom wording suitable for different locales.
Default value
"en": {
"propertyUnknownType": "'{{name}}' property is with undefined 'type' member!",
"propertyInvalidValue": "Invalid '{{name}}' property value! Actual value: {{actualValue}}, Expected value: {{value}}!",
"propertyInvalidValueType": "Invalid '{{name}}' property value type! Actual type: {{actualType}}, Expected type: {{type}}!",
"elementNotInDOM": "Element does not exist in DOM! Please, add the element to the DOM, before invoking a method.",
"moduleUndefined": "Module is undefined.",
"missingReference": "{{elementType}}: Missing reference to {{files}}.",
"htmlTemplateNotSuported": "{{elementType}}: Browser doesn't support HTMLTemplate elements.",
"invalidTemplate": "{{elementType}}: '{{property}}' property accepts a string that must match the id of an HTMLTemplate element from the DOM."
}
Example
Set the messages property.
<smart-toast messages='{"de":{"propertyUnknownType":"Die Eigenschaft '{{name}}' hat ein nicht definiertes 'type'-Member!","propertyInvalidValue":"Ungultiger Eigenschaftswert '{{name}}'! Aktueller Wert: {{actualValue}}, Erwarteter Wert: {{value}}!","propertyInvalidValueType":"Ungultiger Eigenschaftswert '{{name}}'! Aktueller Wert: {{actualType}}, Erwarteter Wert: {{type}}!","elementNotInDOM":"Element existiert nicht in DOM! Bitte fugen Sie das Element zum DOM hinzu, bevor Sie eine Methode aufrufen.","moduleUndefined":"Modul ist nicht definiert.","missingReference":"{{elementType}}: Fehlender Verweis auf {{files}}.","htmlTemplateNotSuported":"{{elementType}}: Browser unterstutzt keine HTMLTemplate-Elemente.","invalidTemplate":"{{elementType}}: '{{property}}' Die Eigenschaft akzeptiert eine Zeichenfolge, die mit der ID eines HTMLTemplate-Elements aus dem DOM ubereinstimmen muss."}}'></smart-toast>
Set the messages property by using the HTML Element's instance.
const toast = document.querySelector('smart-toast');
toast.messages = {"en":{"propertyUnknownType":"'{{name}}' property is with undefined 'type' member!","propertyInvalidValue":"Invalid '{{name}}' property value! Actual value: {{actualValue}}, Expected value: {{value}}!","propertyInvalidValueType":"Invalid '{{name}}' property value type! Actual type: {{actualType}}, Expected type: {{type}}!","elementNotInDOM":"Element does not exist in DOM! Please, add the element to the DOM, before invoking a method.","moduleUndefined":"Module is undefined.","missingReference":"{{elementType}}: Missing reference to {{files}}.","htmlTemplateNotSuported":"{{elementType}}: Browser doesn't support HTMLTemplate elements.","invalidTemplate":"{{elementType}}: '{{property}}' property accepts a string that must match the id of an HTMLTemplate element from the DOM."}};
Get the messages property.
const toast = document.querySelector('smart-toast');
let messages = toast.messages;
modalboolean
When modal mode is enabled, the toast notification is displayed at the center of the screen, overlaying all other page content. The modal property takes precedence over both the position and appendTo properties. If modal is set to true
, any values specified for position and appendTo will be ignored, and the toast will always appear centered in a modal overlay.
Default value
falseExample
Set the modal property.
<smart-toast modal></smart-toast>
Set the modal property by using the HTML Element's instance.
const toast = document.querySelector('smart-toast');
toast.modal = false;
Get the modal property.
const toast = document.querySelector('smart-toast');
let modal = toast.modal;
position"top-left" | "top-right" | "bottom-left" | "bottom-right"
Specifies the area of the browser window where the toast notification will be displayed (for example, "top-right" or "bottom-center"). Note: This position setting is ignored if the appendTo property is defined or if modal mode is enabled, as these options control the toast’s placement instead.
Default value
"top-right"Example
Set the position property.
<smart-toast position='bottom-left'></smart-toast>
Set the position property by using the HTML Element's instance.
const toast = document.querySelector('smart-toast');
toast.position = 'bottom-right';
Get the position property.
const toast = document.querySelector('smart-toast');
let position = toast.position;
readonlyboolean
If the element has the "readonly" attribute, users cannot modify its value; the content is visible but cannot be changed or edited through user input. However, users may still be able to interact with the element in limited ways, such as copying its text, but any form of altering the value is disabled.
Default value
falseExample
Set the readonly property.
<smart-toast readonly></smart-toast>
Set the readonly property by using the HTML Element's instance.
const toast = document.querySelector('smart-toast');
toast.readonly = true;
Get the readonly property.
const toast = document.querySelector('smart-toast');
let readonly = toast.readonly;
rightToLeftboolean
Defines or retrieves a value that specifies whether the element's alignment is adjusted to support right-to-left (RTL) languages, such as Arabic or Hebrew. When enabled, the element's layout and text direction are modified to accommodate locales that use RTL scripts.
Default value
falseExample
Set the rightToLeft property.
<smart-toast right-to-left></smart-toast>
Set the rightToLeft property by using the HTML Element's instance.
const toast = document.querySelector('smart-toast');
toast.rightToLeft = true;
Get the rightToLeft property.
const toast = document.querySelector('smart-toast');
let rightToLeft = toast.rightToLeft;
showCloseButtonboolean
Determines whether the close button is displayed on the toast notification. When set to true, the close button appears, allowing users to manually dismiss the toast. When set to false, the close button is hidden, and the toast can only be dismissed programmatically or by other means. This property can be used to retrieve the current visibility state or update it as needed.
Default value
falseExample
Set the showCloseButton property.
<smart-toast show-close-button></smart-toast>
Set the showCloseButton property by using the HTML Element's instance.
const toast = document.querySelector('smart-toast');
toast.showCloseButton = false;
Get the showCloseButton property.
const toast = document.querySelector('smart-toast');
let showCloseButton = toast.showCloseButton;
themestring
Specifies the theme to be applied to the element. The selected theme controls the visual appearance of the element, including colors, fonts, and overall styling, ensuring a consistent look and feel throughout the user interface.
Default value
""Example
Set the theme property.
<smart-toast theme='blue'></smart-toast>
Set the theme property by using the HTML Element's instance.
const toast = document.querySelector('smart-toast');
toast.theme = 'red';
Get the theme property.
const toast = document.querySelector('smart-toast');
let theme = toast.theme;
type"info" | "warning" | "success" | "error" | "mail" | "time" | null
Applies custom CSS styles and assigns a designated icon to each toast notification item for improved appearance and user experience.
Default value
"info"Example
Set the type property.
<smart-toast type='warning'></smart-toast>
Set the type property by using the HTML Element's instance.
const toast = document.querySelector('smart-toast');
toast.type = 'success';
Get the type property.
const toast = document.querySelector('smart-toast');
let type = toast.type;
unfocusableboolean
When set to true, this property prevents the element from receiving keyboard focus, making it inaccessible through keyboard navigation or programmatic focus methods (such as calling element.focus()).
Default value
falseExample
Set the unfocusable property.
<smart-toast unfocusable></smart-toast>
Set the unfocusable property by using the HTML Element's instance.
const toast = document.querySelector('smart-toast');
toast.unfocusable = false;
Get the unfocusable property.
const toast = document.querySelector('smart-toast');
let unfocusable = toast.unfocusable;
valueany
Assigns a specific text value to the toast notification, determining the message displayed to users within the toast item.
Default value
""Example
Set the value property.
<smart-toast value='Toast !'></smart-toast>
Set the value property by using the HTML Element's instance.
const toast = document.querySelector('smart-toast');
toast.value = Toast !!!;
Get the value property.
const toast = document.querySelector('smart-toast');
let value = toast.value;
Events
itemClickCustomEvent
This event is triggered when a user clicks on a toast notification. It allows you to execute custom logic in response to the user's interaction with the toast item, such as redirecting to a specific page, dismissing the notification, or performing other actions.
- Bubbles Yes
- Cancelable No
- Interface CustomEvent
- Event handler property onItemClick
Arguments
evCustomEvent
Methods
isDefaultPrevented
Returns true if the event was prevented by any of its subscribers.
Returns
boolean true if the default action was prevented. Otherwise, returns false.
preventDefault
The preventDefault() method prevents the default action for a specified event. In this way, the source component suppresses the built-in behavior that follows the event.
stopPropagation
The stopPropagation() method of the Event interface prevents further propagation of the current event in the capturing and bubbling phases.
Example
Set up the event handler of itemClick event.
const toast = document.querySelector('smart-toast'); toast.addEventListener('itemClick', function (event) { // event handling code goes here. })
closeCustomEvent
This event is triggered whenever a toast notification is closed, either by user interaction (such as clicking the close button) or programmatically through code. It allows developers to execute custom logic or cleanup actions after the toast has been dismissed from the user interface.
- Bubbles Yes
- Cancelable No
- Interface CustomEvent
- Event handler property onClose
Arguments
evCustomEvent
Methods
isDefaultPrevented
Returns true if the event was prevented by any of its subscribers.
Returns
boolean true if the default action was prevented. Otherwise, returns false.
preventDefault
The preventDefault() method prevents the default action for a specified event. In this way, the source component suppresses the built-in behavior that follows the event.
stopPropagation
The stopPropagation() method of the Event interface prevents further propagation of the current event in the capturing and bubbling phases.
Example
Set up the event handler of close event.
const toast = document.querySelector('smart-toast'); toast.addEventListener('close', function (event) { // event handling code goes here. })
openCustomEvent
This event is triggered each time a toast notification becomes visible to the user, indicating that the toast item has been fully opened and is now displayed on the screen.
- Bubbles Yes
- Cancelable No
- Interface CustomEvent
- Event handler property onOpen
Arguments
evCustomEvent
Methods
isDefaultPrevented
Returns true if the event was prevented by any of its subscribers.
Returns
boolean true if the default action was prevented. Otherwise, returns false.
preventDefault
The preventDefault() method prevents the default action for a specified event. In this way, the source component suppresses the built-in behavior that follows the event.
stopPropagation
The stopPropagation() method of the Event interface prevents further propagation of the current event in the capturing and bubbling phases.
Example
Set up the event handler of open event.
const toast = document.querySelector('smart-toast'); toast.addEventListener('open', function (event) { // event handling code goes here. })
swipebottomCustomEvent
This event is triggered when a user performs a swipe-down gesture (swipe bottom) on a toast notification item. It can be used to detect and handle user interactions that involve dismissing or interacting with toast messages via a downward swipe.
- Bubbles Yes
- Cancelable No
- Interface CustomEvent
- Event handler property onSwipebottom
Arguments
evCustomEvent
Methods
isDefaultPrevented
Returns true if the event was prevented by any of its subscribers.
Returns
boolean true if the default action was prevented. Otherwise, returns false.
preventDefault
The preventDefault() method prevents the default action for a specified event. In this way, the source component suppresses the built-in behavior that follows the event.
stopPropagation
The stopPropagation() method of the Event interface prevents further propagation of the current event in the capturing and bubbling phases.
Example
Set up the event handler of swipebottom event.
const toast = document.querySelector('smart-toast'); toast.addEventListener('swipebottom', function (event) { // event handling code goes here. })
swipeleftCustomEvent
This event is triggered when a user performs a swipe left gesture on a toast notification item. It allows you to execute custom actions in response to the swipe left interaction with the toast component.
- Bubbles Yes
- Cancelable No
- Interface CustomEvent
- Event handler property onSwipeleft
Arguments
evCustomEvent
Methods
isDefaultPrevented
Returns true if the event was prevented by any of its subscribers.
Returns
boolean true if the default action was prevented. Otherwise, returns false.
preventDefault
The preventDefault() method prevents the default action for a specified event. In this way, the source component suppresses the built-in behavior that follows the event.
stopPropagation
The stopPropagation() method of the Event interface prevents further propagation of the current event in the capturing and bubbling phases.
Example
Set up the event handler of swipeleft event.
const toast = document.querySelector('smart-toast'); toast.addEventListener('swipeleft', function (event) { // event handling code goes here. })
swiperightCustomEvent
This event is triggered when a user performs a swipe-right gesture on a toast notification item. It allows you to handle interactions that occur specifically when the user swipes right on a toast component.
- Bubbles Yes
- Cancelable No
- Interface CustomEvent
- Event handler property onSwiperight
Arguments
evCustomEvent
Methods
isDefaultPrevented
Returns true if the event was prevented by any of its subscribers.
Returns
boolean true if the default action was prevented. Otherwise, returns false.
preventDefault
The preventDefault() method prevents the default action for a specified event. In this way, the source component suppresses the built-in behavior that follows the event.
stopPropagation
The stopPropagation() method of the Event interface prevents further propagation of the current event in the capturing and bubbling phases.
Example
Set up the event handler of swiperight event.
const toast = document.querySelector('smart-toast'); toast.addEventListener('swiperight', function (event) { // event handling code goes here. })
swipetopCustomEvent
This event is triggered when a user performs an upward swipe gesture (swipe top) on a toast notification item.
- Bubbles Yes
- Cancelable No
- Interface CustomEvent
- Event handler property onSwipetop
Arguments
evCustomEvent
Methods
isDefaultPrevented
Returns true if the event was prevented by any of its subscribers.
Returns
boolean true if the default action was prevented. Otherwise, returns false.
preventDefault
The preventDefault() method prevents the default action for a specified event. In this way, the source component suppresses the built-in behavior that follows the event.
stopPropagation
The stopPropagation() method of the Event interface prevents further propagation of the current event in the capturing and bubbling phases.
Example
Set up the event handler of swipetop event.
const toast = document.querySelector('smart-toast'); toast.addEventListener('swipetop', function (event) { // event handling code goes here. })
Methods
closeAll(): void
Closes all currently displayed toast notifications, ensuring that any active toast messages are dismissed from the user interface.
Invoke the closeAll method.
const toast = document.querySelector('smart-toast'); toast.closeAll();
closeItem( item: HTMLElement | string): void
Closes a specific toast notification. This action targets and dismisses the designated toast message from the user interface, ensuring that only the selected toast item is removed without affecting others.
Arguments
itemHTMLElement | string
The toast item (or its id) to remove.
Invoke the closeItem method.
const toast = document.querySelector('smart-toast'); toast.closeItem("item5");
closeLast(): void
Closes the most recently displayed toast notification, removing it from the user's view.
Invoke the closeLast method.
const toast = document.querySelector('smart-toast'); toast.closeLast();
open( value?: HTMLElement | string, iconType?: string): HTMLElement
Displays a new toast notification and returns the corresponding smart-toast-item instance representing the newly created toast. This allows further manipulation or customization of the toast after it appears.
Arguments
value?HTMLElement | string
The value for the toast item. If not set, the value property will be used.
iconType?string
The icon name for the toast item. If not set, the type property determines the icon type that will be used.
ReturnsHTMLElement
Invoke the open method.
const toast = document.querySelector('smart-toast'); const result = toast.open();
CSS Variables
--smart-toast-item-iconvar()
Default value
"''"Code of toast item icon
--smart-toast-container-default-widthvar()
Default value
"var(--smart-bar-width)"Default width of the smartToast's containers, positioned top-left, top-right, bottom-left, bottom-right
--smart-toast-header-heightvar()
Default value
"20px"smartToast header height
--smart-toast-info-backgroundvar()
Default value
"#5bc0de"Background color for type info
--smart-toast-info-colorvar()
Default value
"#fff"Text color for type info
--smart-toast-warning-backgroundvar()
Default value
"#f0ad4e"Background color for type warning
--smart-toast-warning-colorvar()
Default value
"#fff"Text color for type warning
--smart-toast-error-backgroundvar()
Default value
"var(--smart-error)"Background color for type error
--smart-toast-error-colorvar()
Default value
"var(--smart-error-color)"Text color for type error
--smart-toast-success-backgroundvar()
Default value
"var(--smart-success)"Background color for type success
--smart-toast-success-colorvar()
Default value
"var(--smart-success-color)"Text color for type success