Dialog
A box over the page for a focused task. It is the native <dialog>: the keyboard stays inside it, Esc closes it, and focus goes back to the button that opened it. On phones it slides up as a bottom sheet.
Basic
Give a button data-momo-dialog="id". Buttons with data-momo-close close it. Clicking outside does not close it, so typed text is never lost.
<button class="btn btn-brand" type="button" data-momo-dialog="d-project"><i class="mi mi-plus"></i> Create project</button>
<dialog class="dialog" id="d-project" aria-labelledby="d-project-title">
<div class="dialog-header">
<h2 class="dialog-title" id="d-project-title">Create project</h2>
<button class="btn btn-icon btn-sm btn-ghost" type="button" data-momo-close aria-label="Close"><i class="mi mi-x"></i></button>
</div>
<div class="dialog-body">
<p class="text-muted">Deploy your new project in one click.</p>
<div class="form-field">
<label class="form-label" for="dp-name">Name</label>
<input class="form-control" id="dp-name" placeholder="Name of your project" autofocus>
</div>
<div class="form-field">
<label class="form-label" for="dp-fw">Framework</label>
<select class="form-select" id="dp-fw"><option>Momo</option><option>Plain HTML</option></select>
</div>
</div>
<div class="dialog-footer">
<button class="btn btn-ghost" type="button" data-momo-close>Cancel</button>
<button class="btn btn-brand" type="button" data-momo-close value="deploy">Deploy</button>
</div>
</dialog>Confirm
.dialog-alert is a short question with an icon tile. Add data-momo-close-outside when a click outside should cancel.
<button class="btn" type="button" data-momo-dialog="d-delete"><i class="mi mi-trash-2"></i> Delete task</button>
<dialog class="dialog dialog-alert" id="d-delete" aria-labelledby="d-delete-title" aria-describedby="d-delete-text" data-momo-close-outside>
<div class="dialog-body">
<span class="dialog-icon bg-red"><i class="mi mi-trash-2"></i></span>
<div>
<h2 class="dialog-title" id="d-delete-title">Delete this task?</h2>
<p id="d-delete-text" class="text-muted">"Design search page" and its 4 comments will be gone for good.</p>
</div>
</div>
<div class="dialog-footer dialog-footer-plain">
<button class="btn btn-ghost" type="button" data-momo-close autofocus>Keep it</button>
<button class="btn btn-red" type="button" data-momo-close value="delete">Delete</button>
</div>
</dialog>Drawer
.dialog-drawer slides in from the right as a side panel (.dialog-drawer-start from the left). Good for filters and details. The Drawer page has every side, sizes and a site menu.
<button class="btn" type="button" data-momo-dialog="d-filters"><i class="mi mi-sliders-horizontal"></i> Filters</button>
<dialog class="dialog dialog-drawer" id="d-filters" aria-labelledby="d-filters-title">
<div class="dialog-header">
<h2 class="dialog-title" id="d-filters-title">Filters</h2>
<button class="btn btn-icon btn-sm btn-ghost" type="button" data-momo-close aria-label="Close"><i class="mi mi-x"></i></button>
</div>
<div class="dialog-body">
<fieldset class="check-group">
<legend class="form-label">Status</legend>
<label class="check"><input type="checkbox" checked> Paid</label>
<label class="check"><input type="checkbox" checked> Pending</label>
<label class="check"><input type="checkbox"> Unpaid</label>
</fieldset>
<div class="form-field">
<label class="form-label" for="df-method">Method</label>
<select class="form-select" id="df-method"><option>Any</option><option>Credit card</option><option>PayPal</option></select>
</div>
</div>
<div class="dialog-footer">
<button class="btn btn-ghost" type="button" data-momo-close>Reset</button>
<button class="btn btn-brand" type="button" data-momo-close>Show results</button>
</div>
</dialog>Sizes
.dialog-sm (24rem), default (32rem), .dialog-lg (48rem), .dialog-full. Long content scrolls inside .dialog-body while the header and footer stay put. .dialog-center keeps a phone dialog in the middle instead of a sheet.
Toast
A short message in the corner that goes away by itself after 5 seconds (it waits while you hover or focus it). Call Momo.toast(), or give a button data-momo-toast.
<button class="btn" type="button" data-momo-toast="Settings saved" data-momo-toast-text="Your changes are live." data-momo-toast-color="green">Save</button>
<button class="btn" type="button" data-momo-toast="Upload failed" data-momo-toast-text="The file is over 10 MB." data-momo-toast-color="red">Upload</button>
<button class="btn" type="button" data-momo-toast="New message" data-momo-toast-text="Sarah tagged you in Q3 roadmap." data-momo-toast-icon="message-square">Message</button>Momo.toast({
title: 'Task deleted',
text: 'Design search page',
color: 'yellow',
icon: 'trash-2',
timeout: 8000, // 0 = stays until closed
action: { label: 'Undo', onClick: () => restore() },
});Toasts sit above dialogs, and screen readers announce them (errors right away, others politely).
Several at once
They pile up in the corner: the newest in front, two more peeking out behind it, each a little smaller. Hover the pile (or Tab into it) and it fans out into a list, and every toast waits while you read. Up to 5 are kept; a sixth closes the oldest. Swipe one sideways to dismiss it.
<button class="btn btn-brand" type="button" id="toast-many"><i class="mi mi-layers"></i> Show four</button>
<button class="btn" type="button" data-momo-toast="Copied" data-momo-toast-text="The link is on your clipboard." data-momo-toast-icon="copy">One more</button>
<script>
document.getElementById('toast-many').addEventListener('click', function () {
var list = [
{ title: 'Order #10421 paid', text: '$129.00 from Max Ruiz', color: 'green', icon: 'credit-card' },
{ title: 'New comment', text: 'Ana: "Can this ship by Friday?"', icon: 'message-circle' },
{ title: 'Low stock', text: 'Momo Mug: 4 left', color: 'orange', icon: 'package' },
{ title: 'Backup finished', text: 'All 2,318 files are safe.', color: 'cyan', icon: 'cloud' },
];
list.forEach(function (o, i) { setTimeout(function () { Momo.toast(o); }, i * 350); });
});
</script>Where they appear
Bottom right by default. Set it once for the whole page on <body>: top-start, top-center, top-end, bottom-start, bottom-center or bottom-end. Start and end follow the page's direction. On phones they take the full width.
<body data-momo-toast-position="top-center">JavaScript
Momo.dialog.open('d-project');
document.getElementById('d-project').addEventListener('close', (e) => {
console.log(e.target.returnValue); // "deploy" when that button closed it
});Accessibility
- Name the dialog with
aria-labelledbypointing at its title. - Put
autofocuson the first field, or on the safe button in a confirm. - Focus stays inside while it is open and returns to the opener after.