menuMDUIDocs
color_lens
The new mdui 2 based on Material Design 3 and Web Components is now available. Check out the mdui 2 documentation.

Snackbar

Snackbar displays a small pop-up box at the bottom of the window, which can disappear automatically after a timeout or after the user clicks or touches elsewhere on the screen.

Only one Snackbar can be displayed on a screen at a time. If the next Snackbar is opened before the current one is closed, the next Snackbar will be added to the queue and opened after the current one is closed.

Usage

Call the method mdui.snackbar(params).

Usage

Snackbar is called directly by JavaScript, no HTML layout is needed.

There are two ways to call Snackbar:

  • mdui.snackbar(message, params)
  • mdui.snackbar(params)

The return values for both methods are instances of Snackbar.

Parameters supported by Snackbar:

Param NameTypeDefaultDescription
messagestringThe text of the Snackbar. When calling via mdui.snackbar(params), this parameter cannot be empty.
timeoutint4000The delay time for Snackbar to automatically hide, in milliseconds. Set to 0 to keep it open.
positionstringbottomThe position of the Snackbar.
  • bottom: Bottom
  • top: Top
  • left-top: Top left
  • left-bottom: Bottom left
  • right-top: Top right
  • right-bottom: Bottom right
buttonTextstringThe text of the button.
buttonColorstring#90CAF9The text color of the button, which can be a color name or color value, such as red, #ffffff, rgba(255, 255, 255, 0.3), etc.
closeOnButtonClickbooleantrueWhether to close the Snackbar when the button is clicked.
closeOnOutsideClickbooleantrueWhether to close the Snackbar when clicking or touching an area outside the Snackbar.
onClickfunctionCallback function when the Snackbar is clicked.
onButtonClickfunctionCallback function when the button on the Snackbar is clicked.
onOpenfunctionCallback function when the Snackbar starts opening.
onOpenedfunctionCallback function after the Snackbar is opened.
onClosefunctionCallback function when the Snackbar starts closing.
onClosedfunctionCallback function after the Snackbar is closed.

Methods of the Snackbar instance:

Method NameDescription
closeClose the Snackbar. After closing, the Snackbar will be destroyed.

Example

Regular Snackbar

Example
mdui.snackbar({
  message: 'Message sent'
});

Snackbar with callbacks

Example
mdui.snackbar({
  message: 'Archived',
  buttonText: 'undo',
  onClick: function(){
    mdui.alert('Snackbar clicked');
  },
  onButtonClick: function(){
    mdui.alert('Button clicked');
  },
  onClose: function(){
    mdui.alert('Closed');
  }
});

Snackbar in different positions

Example
mdui.snackbar({
  message: 'bottom',
  position: 'bottom',
});

mdui.snackbar({
  message: 'top',
  position: 'top',
});

mdui.snackbar({
  message: 'left-top',
  position: 'left-top',
});

mdui.snackbar({
  message: 'left-bottom',
  position: 'left-bottom',
});

mdui.snackbar({
  message: 'right-top',
  position: 'right-top',
});

mdui.snackbar({
  message: 'right-bottom',
  position: 'right-bottom',
});