MDUIDocs
Copy llms.txt linkCopy llms-full.txt linkView this page in MarkdownDiscuss this page with ChatGPTDiscuss full project docs with ChatGPT
Preset Colors
Custom Color
Extract from Wallpaper
Please select a wallpaper
Getting Started
AI-Assisted Development
Styles
Integration with Frameworks
Components
Avatar Badge BottomAppBar Button ButtonIcon Card Checkbox Chip CircularProgress Collapse Dialog Divider Dropdown Fab Icon Layout LinearProgress List Menu NavigationBar NavigationDrawer NavigationRail Radio RangeSlider Select SegmentedButton Slider Snackbar Switch Tabs TextField Tooltip TopAppBar
Functions
Libraries

Snackbar

Snackbars provide brief updates about app processes at the bottom of the screen.

In addition to direct component usage, mdui also offers a mdui.snackbar function for a simpler way to use the Snackbar component.

Usage

Import the component:

import 'mdui/components/snackbar.js';

Import the TypeScript type:

import type { Snackbar } from 'mdui/components/snackbar.js';

Example:

Photo archived Open Snackbar
<mdui-snackbar class="example-snackbar">Photo archived</mdui-snackbar>

<mdui-button>Open Snackbar</mdui-button>

<script>
  const snackbar = document.querySelector(".example-snackbar");
  const openButton = snackbar.nextElementSibling;

  openButton.addEventListener("click", () => snackbar.open = true);
</script>

Examples

Placement

You can set the snackbar's position using the placement attribute.

Action Button

The action attribute adds an action button on the right side and specifies its text. The action-click event is triggered when the action button is clicked. The action-loading attribute displays a loading state on the action button.

The action slot can also be used to add elements on the right side.

Closeable

The closeable attribute adds a close button on the right. Clicking the button closes the snackbar and triggers the close event.

The close-button slot specifies the close button's content.

The close-icon attribute sets the Material Icon in the default close button. The close-icon slot sets the icon element in the default close button.

Text Lines

The message-line attribute limits the number of lines in the message text, with a maximum of 2 lines.

Auto Close Delay

The auto-close-delay attribute sets the delay for automatic closure, in milliseconds. The default is 5000 milliseconds.

Closing on Outside Click

The close-on-outside-click attribute closes the snackbar when clicking outside of its area.

API

Properties

AttributePropertyReflectTypeDefault
openopenbooleanfalse

Opens the Snackbar.

placementplacement'top' | 'top-start' | 'top-end' | 'bottom' | 'bottom-start' | 'bottom-end''bottom'

Snackbar placement. Default is bottom. Possible values:

  • top: Top center.
  • top-start: Top left.
  • top-end: Top right.
  • bottom: Bottom center.
  • bottom-start: Bottom left.
  • bottom-end: Bottom right.
actionactionstring-

Text for the action button. Alternatively, use slot="action".

action-loadingactionLoadingbooleanfalse

Whether the action button is in a loading state.

closeablecloseablebooleanfalse

Shows a close button on the right.

close-iconcloseIconstring-

Material Icons name for the close button. Alternatively, use slot="close-icon".

message-linemessageLine1 | 2-

Maximum lines for message text. Default is unlimited. Possible values:

  • 1: Single line.
  • 2: Two lines.
auto-close-delayautoCloseDelaynumber5000

Automatically closes the Snackbar after the given delay (in milliseconds). Set to 0 to disable auto-close. Default is 5000.

close-on-outside-clickcloseOnOutsideClickbooleanfalse

Closes the Snackbar when the user clicks or touches outside it.

Events

Name
open

Emitted when the snackbar starts to open. Can be prevented with event.preventDefault().

opened

Emitted after the snackbar opens and animations complete.

close

Emitted when the snackbar starts to close. Can be prevented with event.preventDefault().

closed

Emitted after the snackbar closes and animations complete.

action-click

Emitted when the action button is clicked.

Slots

Name
(default)

Snackbar message.

action

Right action button.

close-button

Right-side close button. Shown if closeable is set.

close-icon

Icon in the right close button.

CSS Parts

Name
message

Message text.

action

Action button.

close-button

Close button.

close-icon

Icon in the close button.

CSS Custom Properties

Name
--shape-corner

The corner radius of the component. You can use a specific pixel value, but it is recommended to reference design tokens.

--z-index

The CSS z-index value of the component.

On this page