Toasts
React Bootstrap 5 Toasts component
Toasts built with Bootstrap 5, React 18 and Material Design 2.0. Non-disruptive notification message in the corner of the interface. It provides quick "at-a-glance" feedback on the outcome of an action.
Push notifications to your visitors with a 'toast', a lightweight and easily customizable alert message. Toasts are designed to mimic the push notifications that have been popularized by mobile and desktop operating systems.
Note: Read the API tab to find all available options and advanced customization
Basic example
Click the buttons to launch the toasts.
Static example
Colors
Placement
You can set position of every notification using
position
property.
Select horizontal / vertical alignment
Current position: top-right
Offset
You can also change offset or any style of a notification using
style
property.
Container
You can display notification anywhere. Just put your toast in your target element and fill
containerRef
property with a reference to the parent.
Stacking
You can create stacking notifications using
MDBStack
component.
Stacking (container)
Add position-relative
class to your container and wrap notifications with
MDBStack
component. Stack component must have position-absolute
class.
Toasts - API
Import
Properties
MDBToast
Name | Type | Default | Description | Example |
---|---|---|---|---|
appendToBody
|
Boolean | false |
Appends element to the end of the body |
<MDBToast appendToBody />
|
autohide
|
Boolean | false |
Toasts will hide automatically or not |
<MDBToast autohide />
|
bodyClasses
|
String | '' |
Add custom class to the body of MDBToast |
<MDBToast bodyClasses="class" />
|
bodyContent
|
String | Node | '' |
Defines a body content for MDBToast |
<MDBToast bodyContent={
Sample
} />
|
closeBtnClasses
|
String | '' |
Add custom class to the close button of MDBToast |
<MDBToast closeBtnClasses="class" />
|
color
|
String | '' |
Allows to set the color of a toast - primary | secondary | secondary | danger | warning | info | light | dark |
<MDBToast color='secondary' />
|
containerRef
|
Reference | '' |
Defines a reference to the parent element |
<MDBToast containerRef={containerReference} />
|
delay
|
Number | 1000 |
Sets the length of animation delay (in ms) |
<MDBToast delay={2000} />
|
headerClasses
|
String | '' |
Add custom class to the header of MDBToast |
<MDBToast headerClasses="class" />
|
headerContent
|
String | Node | '' |
Defines a header content for MDBToast |
<MDBToast headerContent={
Sample
} />
|
position
|
'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right' | '' |
Sets a toast position |
<MDBToast position='top-right' />
|
open
|
Boolean | undefined |
Defines toast's open state.
Usually used with onClose event handler.
|
<MDBToast open />
|
defaultOpen
|
Boolean | false |
Defines toast's default open state. No onClose handler is needed to close the toast.
|
<MDBToast defaultOpen />
|
toastRef
|
React.MutableRefObject | '' |
Reference to the MDBToast element |
<MDBToast toastRef={toastRefference} />
|
width
|
Number | String | '' |
Sets width of toast (in pixels) |
<MDBToast width={300} />
|
initialAnimation
|
boolean | false |
Defines if component should animate on initial render |
<MDBAlert initialAnimation />
|
animationVariants
|
{
open?: Record<string, any>;
closed?: Record<string, any>;
};
|
{open: { opacity: 1 },
closed: { opacity: 0 }}
|
Defines animation variants |
<MDBAlert animationVariants={
{open: { opacity: 1 },
closed: { opacity: 0 }}
} />
|
Events
onOpen
|
() => void | Fired when the Alert starts to open. |
onOpened
|
() => void | Fired after opening transition has completed. |
onClose
|
() => void | Fires immediately when the Alert demands to be closed. |
onClosed
|
() => void | Fired after closing transition has completed. |
CSS variables
As part of MDB’s evolving CSS variables approach, toast now use local CSS variables on
.toast
for enhanced real-time customization. Values for the CSS variables are set
via Sass, so Sass customization is still supported, too.