JavaScript/jQuery Toast Options
An object defining configuration properties for the Toast UI component.
See Also
accessKey
Specifies the shortcut key that sets focus on the UI component.
The value of this property will be passed to the accesskey
attribute of the HTML element that underlies the UI component.
animation
The following code shows default values of the object depending on the device type:
{ show: { type: 'fade', duration: 400, from: 0, to: 1 }, hide: { type: 'fade', duration: 400, from: 1, to: 0 } }
{ show: { type: 'slide', duration: 200, from: { position: { my: 'top', at: 'bottom', of: window } } }, hide: { type: 'slide', duration: 200, to: { position: { my: 'top', at: 'bottom', of: window } } } }
Set the animation object to null
or undefined
to disable animations.
closeOnClick
A Boolean value specifying whether or not the toast is closed if a user clicks it.
closeOnSwipe
A Boolean value specifying whether or not the toast is closed if a user swipes it out of the screen boundaries.
deferRendering
Specifies whether to render the UI component's content when it is displayed. If false, the content is rendered immediately.
displayTime
The time span in milliseconds during which the Toast UI component is visible.
focusStateEnabled
Specifies whether the UI component can be focused using keyboard navigation.
height
Specifies the UI component's height.
This property accepts a value of one of the following types:
Number
The height in pixels.String
A CSS-accepted measurement of height. For example,"55px"
,"20vh"
,"auto"
,"inherit"
.Function (deprecated since v21.2)
Refer to the W0017 warning description for information on how you can migrate to viewport units.
The Toast calculates its height relative to one of the elements in the following priority: position.of => window.
hideOnOutsideClick
Specifies whether to hide the UI component if a user clicks outside it.
Event (jQuery or EventObject)
The event that caused UI component hiding. It is a EventObject or a jQuery.Event when you use jQuery.
true if the UI component should be hidden; otherwise false.
The function passed to this property enables you to specify a custom condition for UI component hiding. For instance, you can prevent hiding until a user clicks a certain element.
jQuery
$(function () { $("#toastContainer").dxToast({ // ... hideOnOutsideClick: function(e) { return e.target === $("#someElement").get()[0]; } }); });
Angular
import { DxToastModule } from "devextreme-angular"; // ... export class AppComponent { // ... hideOnOutsideClick(e) { return e.target === document.getElementById("someElement"); } } @NgModule({ imports: [ // ... DxToastModule ], // ... })
<dx-toast ... [hideOnOutsideClick]="hideOnOutsideClick"> </dx-toast>
Vue
<template> <DxToast .... :hide-on-outside-click="hideOnOutsideClick"> </DxToast> </template> <script> import 'devextreme/dist/css/dx.light.css'; import DxToast from 'devextreme-vue/toast'; export default { components: { DxToast }, methods: { hideOnOutsideClick (e) { return e.target === document.getElementById("someElement"); } } } </script>
React
import React from 'react'; import 'devextreme/dist/css/dx.light.css'; import Toast from 'devextreme-react/toast'; const hideOnOutsideClick = (e) => { return e.target === document.getElementById("someElement"); }; export default function App() { return ( <Toast ... hideOnOutsideClick={hideOnOutsideClick}> </Toast> ); }
The hideOnOutsideClick function is called when a user clicks the UI component or outside it.
hideOnParentScroll
Specifies whether to hide the Toast when users scroll one of its parent elements.
hint
Specifies text for a hint that appears when a user pauses on the UI component.
hoverStateEnabled
Specifies whether the UI component changes its state when a user pauses on it.
maxHeight
Specifies the maximum height the UI component can reach while resizing.
This property accepts a value of one of the following types:
Number
The height in pixels.String
A CSS-accepted measurement of height. For example,"55px"
,"20vh"
,"inherit"
.Function (deprecated since v21.2)
Refer to the W0017 warning description for information on how you can migrate to viewport units.
maxWidth
Specifies the maximum width the UI component can reach while resizing.
This property accepts a value of one of the following types:
Number
The width in pixels.String
A CSS-accepted measurement of width. For example,"55px"
,"20vw"
,"auto"
,"inherit"
.Function (deprecated since v21.2)
Refer to the W0017 warning description for information on how you can migrate to viewport units.
minHeight
Specifies the minimum height the UI component can reach while resizing.
This property accepts a value of one of the following types:
Number
The height in pixels.String
A CSS-accepted measurement of height. For example,"55px"
,"20vh"
,"inherit"
.Function (deprecated since v21.2)
Refer to the W0017 warning description for information on how you can migrate to viewport units.
minWidth
Specifies the minimum width the UI component can reach while resizing.
This property accepts a value of one of the following types:
Number
The width in pixels.String
A CSS-accepted measurement of width. For example,"55px"
,"20vw"
,"auto"
,"inherit"
.Function (deprecated since v21.2)
Refer to the W0017 warning description for information on how you can migrate to viewport units.
onContentReady
A function that is executed when the UI component is rendered and each time the component is repainted.
Information about the event.
Name | Type | Description |
---|---|---|
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
component |
The UI component's instance. |
onDisposing
A function that is executed before the UI component is disposed of.
Information about the event.
Name | Type | Description |
---|---|---|
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
component |
The UI component's instance. |
onHidden
A function that is executed after the UI component is hidden.
Information about the event.
Name | Type | Description |
---|---|---|
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
component |
The UI component's instance. |
onHiding
A function that is executed before the UI component is hidden.
Information about the event.
Name | Type | Description |
---|---|---|
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
component |
The UI component's instance. |
|
cancel |
Set this field to true if you want the Toast to remain visible. |
onInitialized
A function used in JavaScript frameworks to save the UI component instance.
Information about the event.
Name | Type | Description |
---|---|---|
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
component |
The UI component's instance. |
Angular
<dx-toast ... (onInitialized)="saveInstance($event)"> </dx-toast>
import { Component } from "@angular/core"; import Toast from "devextreme/ui/data_grid"; // ... export class AppComponent { toastInstance: Toast; saveInstance (e) { this.toastInstance = e.component; } }
Vue
<template> <div> <DxToast ... @initialized="saveInstance"> </DxToast> </div> </template> <script> import DxToast from 'devextreme-vue/toast'; export default { components: { DxToast }, data: function() { return { toastInstance: null }; }, methods: { saveInstance: function(e) { this.toastInstance = e.component; } } }; </script>
<template> <div> <DxToast ... @initialized="saveInstance"> </DxToast> </div> </template> <script setup> import DxToast from 'devextreme-vue/toast'; let toastInstance = null; const saveInstance = (e) => { toastInstance = e.component; } </script>
React
import Toast from 'devextreme-react/toast'; class App extends React.Component { constructor(props) { super(props); this.saveInstance = this.saveInstance.bind(this); } saveInstance(e) { this.toastInstance = e.component; } render() { return ( <div> <Toast onInitialized={this.saveInstance} /> </div> ); } }
See Also
onOptionChanged
A function that is executed after a UI component property is changed.
Information about the event.
Name | Type | Description |
---|---|---|
value | any |
The modified property's new value. |
previousValue | any |
The UI component's previous value. |
name |
The modified property if it belongs to the first level. Otherwise, the first-level property it is nested into. |
|
fullName |
The path to the modified property that includes all parent properties. |
|
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
component |
The UI component's instance. |
The following example shows how to subscribe to component property changes:
jQuery
$(function() { $("#toastContainer").dxToast({ // ... onOptionChanged: function(e) { if(e.name === "changedProperty") { // handle the property change here } } }); });
Angular
<dx-toast ... (onOptionChanged)="handlePropertyChange($event)"> </dx-toast>
import { Component } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { // ... handlePropertyChange(e) { if(e.name === "changedProperty") { // handle the property change here } } }
import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { DxToastModule } from 'devextreme-angular'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, DxToastModule ], providers: [ ], bootstrap: [AppComponent] }) export class AppModule { }
Vue
<template> <DxToast ... @option-changed="handlePropertyChange" /> </template> <script> import 'devextreme/dist/css/dx.light.css'; import DxToast from 'devextreme-vue/toast'; export default { components: { DxToast }, // ... methods: { handlePropertyChange: function(e) { if(e.name === "changedProperty") { // handle the property change here } } } } </script>
React
import React from 'react'; import 'devextreme/dist/css/dx.light.css'; import Toast from 'devextreme-react/toast'; const handlePropertyChange = (e) => { if(e.name === "changedProperty") { // handle the property change here } } export default function App() { return ( <Toast ... onOptionChanged={handlePropertyChange} /> ); }
onShowing
A function that is executed before the UI component is displayed.
Information about the event.
Name | Type | Description |
---|---|---|
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
component |
The UI component's instance. |
|
cancel |
Set this field to true if you want to prevent the Toast from being displayed. |
onShown
A function that is executed after the UI component is displayed.
Information about the event.
Name | Type | Description |
---|---|---|
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
component |
The UI component's instance. |
position
Positions the UI component.
rtlEnabled
Switches the UI component to a right-to-left representation.
When this property is set to true, the UI component text flows from right to left, and the layout of elements is reversed. To switch the entire application/site to the right-to-left representation, assign true to the rtlEnabled field of the object passed to the DevExpress.config(config) method.
DevExpress.config({ rtlEnabled: true });
shading
Specifies whether to shade the background when the UI component is active.
shadingColor
Specifies the shading color. Applies only if shading is enabled.
This property supports the following colors:
- Hexadecimal colors
- RGB colors
- RGBA colors
- Predefined/cross-browser color names
- Predefined SVG colors
- Paint server address
tabIndex
Specifies the number of the element when the Tab key is used for navigating.
The value of this property will be passed to the tabindex
attribute of the HTML element that underlies the UI component.
type
Specifies the Toast UI component type.
The available toast types (except for "custom") only differ by the icon and background color.
If you assign "custom" to the type property, the dx-toast-custom
class is applied to the UI component element. Use CSS styles to customize the appearance of the toast.
visible
A Boolean value specifying whether or not the UI component is visible.
You can show and hide the UI component by changing the value of an observable variable passed to this property.
The UI component is automatically hidden after the time specified in the displayTime property.
width
Specifies the UI component's width.
This property accepts a value of one of the following types:
Number
The width in pixels.String
A CSS-accepted measurement of width. For example,"55px"
,"20vw"
,"auto"
,"inherit"
.Function (deprecated since v21.2)
Refer to the W0017 warning description for information on how you can migrate to viewport units.
The Toast calculates its width relative to one of the elements in the following priority: position.of => window.
wrapperAttr
Specifies the global attributes for the UI component's wrapper element.
jQuery
$(function(){ $("#toastContainer").dxToast({ // ... wrapperAttr: { id: "elementId", class: "class-name" } }); });
Angular
<dx-toast ... [wrapperAttr]="{ id: 'elementId', class: 'class-name' }"> </dx-toast>
import { Component } from '@angular/core'; // ... @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { // ... }
import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { DxToastModule } from 'devextreme-angular'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, DxToastModule ], providers: [ ], bootstrap: [AppComponent] }) export class AppModule { }
Vue
<template> <DxToast ... :wrapper-attr="toastAttributes"> </DxToast> </template> <script> import DxToast from 'devextreme-vue/toast'; export default { components: { DxToast }, data() { return { toastAttributes: { id: 'elementId', class: 'class-name' } } } } </script>
React
import React, { useMemo } from 'react'; import Toast from 'devextreme-react/toast'; function App() { const toastAttributes = useMemo(() => { return { id: 'elementId', class: 'class-name' } }, []); return ( <Toast ... wrapperAttr={toastAttributes}> </Toast> ); } export default App;
The code above specifies the id
and class
attributes for the wrapper element and produces markup similar to this:
<body> <!-- The following is the wrapper element. --> <!-- It is nested inside an element defined by the `container` property (`<body>` by default). --> <div id="elementId" class="dx-overlay-wrapper dx-toast-wrapper class-name" ... > <!-- The following element displays text content and an icon. --> <div class="dx-toast-content" ... > <!-- ... --> </div> </div> </body>
jQuery
You can specify attributes to the component's root element directly in HTML code:
<div id="myToast" class="myClass"></div>
Angular
You can specify attributes to the component's root element directly in HTML code:
<dx-toast ... class="myClass"> </dx-toast>
React
You can specify attributes to the component's root element directly in HTML code:
<Toast ... className="myClass" />
ASP.NET Core Controls
To add an attribute to an ASP.NET Core control, use its OnInitialized method:
@(Html.DevExtreme().Toast()... .OnInitialized("(e) => e.element.addClass('myClass')") )
ASP.NET MVC Controls
To add an attribute to an ASP.NET MVC control, use its OnInitialized method:
@(Html.DevExtreme().Toast()... .OnInitialized("(e) => e.element.addClass('myClass')") )