Feedback
Toast
Short messages that slide in at a corner of the screen and go away on their own: "Saved", "Payment failed". They are sent from PHP (a Livewire action, a controller before a redirect) or from JavaScript, and shown by the toast area that tk:html already places on every page.
tk:toast is the area where the toasts appear; tk:toast.flashed shows toasts flashed before a redirect on pages that persist the area.
Nothing to show
A small card at the bottom right with a green check icon and "Profile saved.", announced to screen readers. It closes by itself after a few seconds (longer for longer texts), with a bar showing the time left; hovering or focusing it pauses the timer, and it can be swiped away or closed with its button.
From a controller or JavaScript #
Outside Livewire, the toast is flashed to the session and shown by the next page rendered: the view this request returns, or the page after a redirect. In JavaScript, tallkit.toast() (or $tallkit.toast() in Alpine) takes the same arguments.
Nothing to show
Options and actions #
An info toast at the top center for 8 seconds, with an Undo button that calls unarchive on the component that sent it.
Nothing to show
Loading and promises #
A toast with a spinner while the promise runs, which turns into a success or an error toast when it settles. toast().loading(message) shows a spinner toast that stays until closed with toast().close(id): in JavaScript, toast() and its shortcuts return the toast's id (const id = tallkit.toast().loading('Saving')).
Nothing to show
The area's methods #
The tk:toast area also has methods of its own, reached with Alpine.$data() on it. Each takes the options and returns the toast, except promise(), which returns the promise:
| Method | What it does |
|---|---|
notify(options) |
Shows a toast, like tallkit.toast(). |
success(title, options), error(), info(), warning() |
A toast of that type with that title. |
loading(title, options), promise(promise, messages) |
Like tallkit.toast().loading() and .promise(), with the text as the title. |
group(options, key) |
Shows one toast per key: sending the same key again restarts its timer and counts the repeats (count) instead of stacking another. |
queue(options, max = 3) |
Closes the oldest visible toast when max are on screen, then shows this one. |
dedupe(options, windowMs = 2000) |
Skips a toast with the same title and type shown within windowMs. |
Nothing to show
Types #
success(), error(), info() and warning() set the type: the icon, the color and how it is announced. They take the message and the title.
Nothing to show
Positions #
position picks the corner: top-left, top-center, top-right, bottom-left, bottom-center or bottom-right.
Nothing to show
Inverted and without a timer #
invert gives a dark card in light mode and a light one in dark mode; duration: false keeps the toast until it is closed.
Nothing to show
Loading until closed #
loading() returns the toast's id; the spinner stays until close(id).
Nothing to show
Skipping duplicates #
The area's dedupe(options) skips a toast with the same title and type shown within the last 2 seconds: click several times and only one appears.
Nothing to show
Reference
tk:toast
tk:toast.flashed
tk:toast
| Prop | Type | Default | Description |
|---|---|---|---|
flashed |
bool | true |
Shows the toasts flashed to the session when the page loads. |
Prefixes
| Prefix | Goes to |
|---|---|
position: |
Each corner's stack. |
container: |
Each toast card. |
title:, message:, actions:, close:, progress: |
The parts of each toast. |
icon: |
The icon of every type, the loading spinner included. |
icon-success:, icon-info:, icon-error:, icon-warning:, icon-loading: |
The icon of one type. |
tk:toast.flashed
| Prop | Type | Default | Description |
|---|---|---|---|
nonce |
string | null |
The CSP nonce of its script. |
Options
Accepted by toast() in PHP and JavaScript, positionally or by name. toast()->success(), ->error(), ->info(), ->warning() set the type; they take message and title in that order, so pass the other options by name.
| Option | Type | Default | Description |
|---|---|---|---|
message |
string | Htmlable | null |
The text. A string is escaped; an HtmlString or a view is rendered as HTML. |
title |
string | Htmlable | null |
A bold line above the message. |
type |
string | null |
success, error, warning, info or loading: the icon and color, and how it is announced (errors and warnings assertively). |
duration |
int | false | by length | Milliseconds before it closes; false keeps it until closed. Without it, the time comes from the length of the text, and a toast with actions stays until closed. |
position |
string | bottom-right |
top-left, top-center, top-right, bottom-left, bottom-center, bottom-right (top and bottom mean right). |
progress |
bool | true |
The bar showing the time left. |
size |
string | md |
The size of the card. |
invert |
bool | false |
Dark card in light mode and light in dark mode. |
actions |
array | null |
Buttons, each with a label and one of: method (with params, called on the Livewire component that sent the toast), event (a Livewire event dispatched with params), or href (a link). In JavaScript, onClick (a function) too. |
id |
string | generated | Updates the toast with the same id instead of adding another (also one still closing, which comes back), and is what close(id) takes. |
JavaScript only, passed by name (tallkit.toast({ message, swipe: false })):
| Option | Type | Default | Description |
|---|---|---|---|
pauseOnHover |
bool | true |
Pauses the timer while the mouse is over the toast. |
swipe |
bool | true |
Lets the toast be swiped away. |
attentionAware |
bool | true |
Pauses the timer while the page is in the background or the user is idle. |
maxStack |
int | false | 5 |
How many toasts stack in its corner before the oldest gives way; false for no limit. |
html |
bool | false |
Renders title and message as HTML. Only for trusted content. |
Customization
tk:html passes toast: attributes to the area. On tk:toast, classes go to the full-screen layer, and the parts take prefixes (listed in the Reference above).
Nothing to show
Accessibility
Each toast is announced through the shared hidden live regions: polite for success, info and loading, assertive for errors and warnings. The timer pauses while the pointer is over the toast or the focus is in it, and while the page is in the background. The close button has an accessible name; closing a toast that has the focus moves it to the next focusable element instead of losing it.
Behavior notes
- Toasts sent from a Livewire action are shown in the same response, without a reload; toasts sent during a request outside Livewire are shown by the next page rendered (this request's own view, or the page after a redirect).
- When a Livewire action redirects, the toasts sent in that request, by any component on the page, are flashed and shown on the next page instead of leaving with this one. The same happens when a component redirects from
mount(), for its toasts and those of the parents still mounting. - Flashed toasts wait in the session until a page shows them (a JSON response does not); only the last 10 are kept. Their actions with
methodare dropped, since the component that would run them is not on the next page. - With
wire:navigatethe area persists between pages (tk:htmluses@persist), so a toast stays visible while the user navigates. - At most five toasts stack in each corner; older ones give way to new ones.
- While a
tk:modalis open, toasts show under its backdrop and cannot be clicked, swiped or closed: the modal makes the rest of the page inert. They are still announced. For feedback inside a modal, put atk:alertin its content.