Draw the snackbar host without Tailwind

Plan step 36 (actions). <x-toast> renders data-md-toast with
data-md-position, its snackbar data-md-toast-snackbar with a bound
data-md-two-line, data-md-toast-content with a bound
data-md-toast-wrap, and data-md-toast-action/-dismiss; no class list.
toast.css draws SnackbarTokens' inverse surface, 48/68px container,
the two 40px controls reaching 48px targets with their own state
layer and touch target (ACT-18), the enter transition and the
position-start margin that grows from medium.

data-toast becomes data-md-toast-snackbar and data-toast-action
becomes data-md-toast-action (snackbar.js, navigation.js's
hide-on-scroll guard, NavigationBarTest, CommunicationTest); a new
data-md-toast-dismiss hook names the close button. ToastTest is
rewritten on the hooks and ComponentStylesheet. CommunicationTest
gains the owed tests: an actioned snackbar past the default timeout,
Escape on a focused one, the live region before any message, and the
two-line height with Alt+G reaching the action from elsewhere on the
page.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qwx5USif3wFFmxtHg5U1g9
This commit is contained in:
Andreas Reinhold / reini
2026-09-14 16:42:05 +02:00
co-authored by Claude Opus 5
parent 8cb8727f75
commit ce8ac4d316
9 changed files with 329 additions and 53 deletions
+58 -5
View File
@@ -42,7 +42,7 @@ class RichTooltipMorphProbe extends Component
// The live region is the host itself, in the page before any message is (actions.md ACT-02).
const SNACKBAR = "document.querySelector('[x-data=\"materialSnackbar\"][aria-live]')";
const TOAST = "document.querySelector('[data-toast]')";
const TOAST = "document.querySelector('[data-md-toast-snackbar]')";
it('shows a toast as a snackbar, then the next in turn', function () {
$page = visit('/material/communication')->waitForEvent('networkidle')
@@ -90,7 +90,7 @@ it('does not let a toast dismissed early cut the next one short', function () {
// A click with no hover or focus before it, as a screen reader activates a button: nothing has
// paused the first toast's timer.
$page->script("document.querySelector('[data-toast] button[aria-label=\"Dismiss\"]').click()");
$page->script("document.querySelector('[data-md-toast-dismiss]').click()");
$page->assertScript(TOAST."?.textContent.includes('Link copied')")
->wait(1.2);
@@ -117,7 +117,7 @@ it('keeps a sticky toast aside while a passing one shows, brings back the newest
$page->assertScript(TOAST."?.textContent.includes('Version 2 is ready')");
$page->click('[data-toast] button[aria-label="Dismiss"]')
$page->click('[data-md-toast-dismiss]')
->assertScript(TOAST.' === null');
// Dismissed rather than left to time out: the pointer still rests where the snackbar appears,
@@ -125,7 +125,7 @@ it('keeps a sticky toast aside while a passing one shows, brings back the newest
$page->script("window.eval(\"materialToast('Link copied', { timeout: 0 })\")");
$page->assertScript(TOAST."?.textContent.includes('Link copied')")
->click('[data-toast] button[aria-label="Dismiss"]')
->click('[data-md-toast-dismiss]')
->assertScript(TOAST.' === null');
});
@@ -135,12 +135,65 @@ it('dispatches a toast action\'s window event alongside its handler, and closes'
$page->script("window.eval(\"window.reloads = 0; window.handled = 0; window.addEventListener('material:test-reload', () => window.reloads++); materialToast('A new version is ready', { sticky: true, action: { label: 'Reload', event: 'material:test-reload', handler: () => window.handled++ } })\")");
$page->click('[data-toast-action]')
$page->click('[data-md-toast-action]')
->assertScript(TOAST.' === null')
->assertScript("window.eval('window.reloads') === 1")
->assertScript("window.eval('window.handled') === 1");
});
it('keeps an actioned snackbar on screen past the default timeout, until it is acted on', function () {
$page = visit('/material/communication')->waitForEvent('networkidle')
->assertScript("document.readyState === 'complete' && typeof window.Alpine !== 'undefined' && typeof window.Livewire !== 'undefined'");
// No timeout written out: M3 forbids an actioned snackbar from auto-dismissing (ACT-03).
$page->script("materialToast('Share deleted', { action: { label: 'Undo', handler: () => {} } })");
$page->assertScript(TOAST."?.textContent.includes('Share deleted')")
->wait(4.5);
$page->assertScript(TOAST."?.textContent.includes('Share deleted')")
->click('[data-md-toast-dismiss]')
->assertScript(TOAST.' === null');
});
it('dismisses a focused snackbar with Escape', function () {
$page = visit('/material/communication')->waitForEvent('networkidle')
->assertScript("document.readyState === 'complete' && typeof window.Alpine !== 'undefined' && typeof window.Livewire !== 'undefined'");
$page->script("materialToast('Share deleted', { action: { label: 'Undo', handler: () => {} } })");
$page->assertScript(TOAST."?.textContent.includes('Share deleted')")
->script("document.querySelector('[data-md-toast-dismiss]').focus()")
->keys(':focus', 'Escape')
->assertScript(TOAST.' === null');
});
it('keeps the snackbar\'s live region in the page, polite, before any message arrives', function () {
$page = visit('/material/communication')->waitForEvent('networkidle')
->assertScript("document.readyState === 'complete' && typeof window.Alpine !== 'undefined' && typeof window.Livewire !== 'undefined'");
$page->assertScript(SNACKBAR.' !== null')
->assertScript(SNACKBAR."?.getAttribute('aria-live') === 'polite'")
->assertScript(SNACKBAR."?.getAttribute('aria-atomic') === 'true'")
->assertScript(TOAST.' === null');
});
it('grows to M3\'s two-line height with a description, and Alt+G reaches its action from anywhere on the page', function () {
$page = visit('/material/communication')->waitForEvent('networkidle')
->assertScript("document.readyState === 'complete' && typeof window.Alpine !== 'undefined' && typeof window.Livewire !== 'undefined'");
$page->script("materialToast('Upload paused', { description: 'The connection dropped at 64%.', action: { label: 'Retry now', handler: () => {} } })");
$page->assertScript(TOAST."?.textContent.includes('Upload paused')")
->assertScript('Math.round('.TOAST.'.getBoundingClientRect().height) === 68');
// Focused somewhere else on the page first: the shortcut has to reach the snackbar from
// wherever the keyboard already was, since a snackbar never takes the focus on its own.
$page->script("document.body.setAttribute('tabindex', '-1'); document.body.focus()")
->keys(':focus', 'Alt+g')
->assertScript('document.activeElement === '.TOAST."?.querySelector('[data-md-toast-action]')");
});
it('opens a persistent rich tooltip on press', function () {
$bubble = "document.querySelector('#communication [role=\"dialog\"][popover]')";