pub struct Toaster<S> { /* private fields */ }Expand description
The corner of the page that shows the toasts in the list toasts.
It is a landmark region named “Notifications” holding an
aria-live="polite" list, so a screen reader reads a toast when it is
added, after what it is reading. Each toast has a button that removes it.
A toast stays until it is dismissed, unless Toaster::dismiss_after
sets a time, because a visitor who reads slowly or uses a magnifier can
miss a notice that leaves by itself (WCAG 2.2.1).
The region sits in the page rather than in the top layer, so an open modal dialog covers it and makes it inert until the dialog closes.
use hypersig::Signals;
use hypersig_ui::{Toast, Toaster};
use serde::{Deserialize, Serialize};
#[derive(Signals, Serialize, Deserialize)]
struct App {
toasts: Vec<Toast>,
}
let toaster = Toaster::new(App::toasts()).render();
let html = toaster.render();
assert!(html.contains(r#"aria-label="Notifications""#));
assert!(html.contains(r#"aria-live="polite""#));Implementations§
Source§impl<S> Toaster<S>
impl<S> Toaster<S>
Sourcepub fn label(self, label: impl Into<String>) -> Self
pub fn label(self, label: impl Into<String>) -> Self
Names the region for assistive technology, in place of “Notifications”.
Sourcepub fn dismiss_after(self, delay: Duration) -> Self
pub fn dismiss_after(self, delay: Duration) -> Self
Removes each toast delay after it appears.
The time runs while the pointer or focus is on the toast, so give it long enough to read the longest toast twice.