snackbar
The snackbar
function provides a simple method to utilize the <mdui-snackbar>
component without the need to write HTML code.
<mdui-button class="example-button">open</mdui-button>
<script type="module">
import { snackbar } from "mdui/functions/snackbar.js";
const button = document.querySelector(".example-button");
button.addEventListener("click", () => {
snackbar({
message: "Photo archived",
action: "Undo",
onActionClick: () => console.log("click action button")
});
});
</script>
API
snackbar(options: Options): Snackbar
The snackbar function accepts an Options object as its parameter and returns an instance of the <mdui-snackbar>
component.
Options
Property | Type | Default |
---|---|---|
message |
string |
- |
The text to display in the snackbar. | ||
placement |
'top' | 'top-start' | 'top-end' | 'bottom' | 'bottom-start' | 'bottom-end' |
bottom |
The position of the snackbar. The default is
|
||
action |
string |
- |
The text for the action button. | ||
closeable |
boolean |
false |
Whether a close button is displayed on the right side. | ||
messageLine |
1 | 2 |
- |
Sets the maximum number of lines for the message text. The default is unlimited. Options include:
|
||
autoCloseDelay |
number |
5000 |
The delay in milliseconds before the snackbar automatically closes. Set to 0 to disable auto-close. The default is 5000 milliseconds (5 seconds). |
||
closeOnOutsideClick |
boolean |
false |
Whether the snackbar should close on outside clicks or touches. | ||
queue |
string |
- |
The queue name. By default, the queue is not enabled. If this function is called multiple times, multiple snackbars will be displayed simultaneously. If a queue name is provided, snackbars with the same queue name will open sequentially, each after the previous one closes. |
||
onClick |
(snackbar: Snackbar) => void |
- |
Callback invoked when the snackbar is clicked. The snackbar instance is passed as a parameter and is also the context of |
||
onActionClick |
(snackbar: Snackbar) => void | boolean | Promise<void> |
- |
Callback invoked when the action button is clicked. The snackbar instance is passed as a parameter and is also the context of By default, the snackbar closes when the action button is clicked. Return |
||
onOpen |
(snackbar: Snackbar) => void |
- |
Callback invoked when the snackbar starts to open. The snackbar instance is passed as a parameter and is also the context of |
||
onOpened |
(snackbar: Snackbar) => void |
- |
Callback invoked when the snackbar opening animation completes. The snackbar instance is passed as a parameter and is also the context of |
||
onClose |
(snackbar: Snackbar) => void |
- |
Callback invoked when the snackbar starts to close. The snackbar instance is passed as a parameter and is also the context of |
||
onClosed |
(snackbar: Snackbar) => void |
- |
Callback invoked when the snackbar closing animation completes. The snackbar instance is passed as a parameter and is also the context of |