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:
co-authored by
Claude Opus 5
parent
8cb8727f75
commit
ce8ac4d316
@@ -18,26 +18,27 @@
|
||||
|
||||
The live region is the host itself, not the snackbar: a region must be in the page before its
|
||||
contents change for a screen reader to announce them reliably, and the snackbar comes and
|
||||
goes. It is `aria-live="polite" aria-atomic="true"`, as M3 asks for a snackbar (never
|
||||
assertive); a `type` picks the region's role — `alert` for an error or a warning, `status`
|
||||
otherwise — and the explicit `aria-live` keeps even those polite.
|
||||
goes (ACT-02). It is `aria-live="polite" aria-atomic="true"`, as M3 asks for a snackbar
|
||||
(never assertive); a `type` picks the region's role — `alert` for an error or a warning,
|
||||
`status` otherwise — and the explicit `aria-live` keeps even those polite.
|
||||
|
||||
Hooks for tests and styling: `data-toast` on the snackbar on screen, `data-toast-action` on its
|
||||
action button.
|
||||
Hooks for tests and styling: `data-md-toast` on the host, `data-md-toast-snackbar` on the
|
||||
snackbar on screen, `data-md-toast-action` on its action button and `data-md-toast-dismiss`
|
||||
on its close button. Drawn by resources/css/components/toast.css.
|
||||
|
||||
`@persist` keeps the host across wire:navigate, so a toast dispatched with `redirectTo` is
|
||||
still on screen when the next page arrives.
|
||||
|
||||
There is no state icon: M3 says to avoid one in a snackbar ("use a dialog instead if an icon
|
||||
feels necessary"), and both lines of the message are plain inverse-on-surface — M3 gives the
|
||||
supporting text no fourth colour and tells the two lines apart by position. The 40px action
|
||||
and close buttons carry `touch-target`, which reaches M3's 48px without growing the container.
|
||||
Escape dismisses a snackbar that holds the focus.
|
||||
feels necessary", ACT-20), and both lines of the message are plain inverse-on-surface — M3
|
||||
gives the supporting text no fourth colour and tells the two lines apart by position. The
|
||||
40px action and close buttons reach M3's 48px target without growing the container (ACT-18).
|
||||
Escape dismisses a snackbar that holds the focus (ACT-34).
|
||||
|
||||
Alt+G moves the focus to a snackbar that carries an action, from wherever the page had it —
|
||||
M3 asks for a documented shortcut on the web, since a snackbar never takes the focus itself
|
||||
and a keyboard has no other way to reach one. It does nothing when the snackbar on screen has
|
||||
no action.
|
||||
and a keyboard has no other way to reach one (ACT-34). It does nothing when the snackbar on
|
||||
screen has no action.
|
||||
|
||||
M3's snackbar (SnackbarTokens, androidx Compose Material 3, Apache-2.0): inverse surface,
|
||||
body-medium text, a label-large action in inverse-primary, extra-small corners, elevation 3,
|
||||
@@ -45,14 +46,19 @@
|
||||
says 64dp, and the token is the more precise of the two). A description is that second line,
|
||||
so the container is pinned to 68px whenever one is there rather than left to grow into it. On
|
||||
a compact window a two-line snackbar with an action wraps the action below the text, which is
|
||||
the third of M3's five snackbar configurations ("two lines with longer action"). `position`: `bottom` (centred, the default) or `bottom-start`. It lifts
|
||||
above a bottom bar through `--material-bottom-bar`, and publishes its own height as
|
||||
`--material-snackbar-height` so a FAB can lift clear of it — M3: a snackbar appears above a
|
||||
FAB, never in front of or behind one. A compact window (below `medium`, 600px) gets the
|
||||
full-width snackbar; from `medium` it hugs its line length instead, as M3 asks. --}}
|
||||
the third of M3's five snackbar configurations ("two lines with longer action"). `position`:
|
||||
`bottom` (centred, the default) or `bottom-start`. It lifts above a bottom bar through
|
||||
`--material-bottom-bar`, and publishes its own height as `--material-snackbar-height` so a
|
||||
FAB can lift clear of it — M3: a snackbar appears above a FAB, never in front of or behind
|
||||
one (ACT-17). A compact window (below `medium`, 600px) gets the full-width snackbar; from
|
||||
`medium` it hugs its line length instead, as M3 asks. --}}
|
||||
|
||||
@props(['position' => 'bottom'])
|
||||
|
||||
@php
|
||||
$position = in_array($position, ['bottom', 'bottom-start'], true) ? $position : 'bottom';
|
||||
@endphp
|
||||
|
||||
@persist('material-toast')
|
||||
<div
|
||||
x-data="materialSnackbar"
|
||||
@@ -60,35 +66,32 @@
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
aria-atomic="true"
|
||||
{{ $attributes->class([
|
||||
'pointer-events-none fixed inset-x-4 z-50 flex bottom-[calc(var(--material-bottom-bar,0px)+1rem)]',
|
||||
'justify-center' => $position !== 'bottom-start',
|
||||
'justify-start medium:start-6' => $position === 'bottom-start',
|
||||
]) }}
|
||||
data-md-toast
|
||||
data-md-position="{{ $position }}"
|
||||
{{ $attributes }}
|
||||
>
|
||||
<template x-if="current">
|
||||
<div
|
||||
x-bind:key="current.id"
|
||||
data-toast
|
||||
data-md-toast-snackbar
|
||||
x-bind:data-md-two-line="current.description ? '' : null"
|
||||
x-on:mouseenter="pause()"
|
||||
x-on:mouseleave="resume()"
|
||||
x-on:focusin="pause()"
|
||||
x-on:focusout="resume()"
|
||||
x-bind:class="current.description ? 'min-h-17' : 'min-h-12'"
|
||||
class="pointer-events-auto flex w-full max-w-[min(100%,36rem)] flex-wrap items-center gap-3 rounded-corner-xs bg-inverse-surface py-1.5 ps-4 pe-2 text-inverse-on-surface shadow-elevation-3 transition-[translate,opacity] duration-(--md-sys-motion-spatial-fast-duration) ease-spatial-fast starting:translate-y-4 starting:opacity-0 medium:w-auto medium:min-w-86"
|
||||
>
|
||||
<div x-bind:class="current.description && current.action ? 'max-medium:basis-full' : ''" class="min-w-0 flex-1 py-1.5">
|
||||
<p class="type-body-md" x-text="current.title"></p>
|
||||
<p class="type-body-md" x-show="current.description" x-text="current.description"></p>
|
||||
<div data-md-toast-content x-bind:data-md-toast-wrap="current.description && current.action ? '' : null">
|
||||
<p data-md-toast-title x-text="current.title"></p>
|
||||
<p data-md-toast-description x-show="current.description" x-text="current.description"></p>
|
||||
</div>
|
||||
|
||||
<template x-if="current.action">
|
||||
<button type="button" data-toast-action class="state-layer focus-ring touch-target ms-auto h-10 shrink-0 rounded-corner-full px-3 type-label-lg text-inverse-primary" x-text="current.action.label" x-on:click="act()"></button>
|
||||
<button type="button" data-md-toast-action x-text="current.action.label" x-on:click="act()"></button>
|
||||
</template>
|
||||
|
||||
<template x-if="current.action || ! current.timeout">
|
||||
<button type="button" class="state-layer focus-ring touch-target inline-flex size-10 shrink-0 items-center justify-center rounded-corner-full" aria-label="{{ __('Dismiss') }}" x-on:click="dismiss()">
|
||||
<x-livewire-material::icon name="close" optical="20" class="size-5" />
|
||||
<button type="button" data-md-toast-dismiss aria-label="{{ __('Dismiss') }}" x-on:click="dismiss()">
|
||||
<x-livewire-material::icon name="close" size="20" />
|
||||
</button>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user