Slide the sheets and close the search view out in Firefox too

The side sheet, the bottom sheet's panel and the docked search's scrim
and view kept `display` alive through their exit with
`transition-behavior: allow-discrete`. Firefox does not transition
`display` (Chrome 117 and Safari 18 do), and `x-show` sets
`display: none` in the frame the exit starts, so in Firefox the sheets
vanished instead of sliding out and the search view and scrim vanished
instead of fading. The docked search had a second problem in every
engine: neither the view nor the scrim had a closed state to transition
to, so where `display` was held (Chrome, Safari) the view stood at full
opacity for its duration and then disappeared.

Each element now carries `x-transition:enter`/`:leave="md-transition"`,
the approach the two sheet scrims already took (renamed from
`md-scrim-transition` to one name for all of them). The class only
switches Alpine to CSS-transition mode, so `x-show` holds `display` for
the element's computed transition-duration before hiding it, in every
engine, and a reopen during the exit cancels the pending hide; nothing
styles it. `display` and `allow-discrete` leave the transitions so
Chrome and Safari do not hold a second time. Alpine reads the first
`transition-duration` listed, which is the closing slide or fade in each
list (the preset panel lists translate before height). The search view
now closes back into the bar (opacity 0, `scale: 1 0.9`, the reverse of
its `@starting-style` entry) and its scrim fades out on close and when
the search turns full screen. Under reduced motion the durations are
zero and every one of them closes at once.

Four browser tests sample each exit mid-way in the page, in the same
round trip as the close: the sheets part of the way to their closed
offset, the search scrim and view part of the way faded, each still
displayed, then `display: none`. All four fail on main in Firefox (the
two search tests in Chrome too) and pass in Chrome, Firefox and Safari.
OverlayTest pins the drawer's new transition and the view's markup.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Andreas Reinhold / reini
2026-09-16 20:26:45 +02:00
co-authored by Claude Opus 5
parent 92e560bef6
commit 15e4fa7ed1
9 changed files with 169 additions and 27 deletions
+9 -7
View File
@@ -31,6 +31,9 @@
* *
* The scrim fades out as it fades in, and the state rules match the root's own scrim and panel, * The scrim fades out as it fades in, and the state rules match the root's own scrim and panel,
* so a sheet nested in an open one (a menu's sheet at compact inside a sheet) keeps its own state. * so a sheet nested in an open one (a menu's sheet at compact inside a sheet) keeps its own state.
* Both keep `x-show`, and the view's `x-transition` holds their `display` through the exit rather
* than `allow-discrete`, which Firefox does not honour for `display` (see drawer.css); Alpine holds
* for the first `transition-duration` listed, so the closing slide is listed first.
*/ */
@layer material.reset, material.tokens, material.base, material.layout, material.components, material.text, material.visibility; @layer material.reset, material.tokens, material.base, material.layout, material.components, material.text, material.visibility;
@@ -85,10 +88,9 @@
box-shadow: var(--md-sys-elevation-1); box-shadow: var(--md-sys-elevation-1);
padding-bottom: var(--material-safe-bottom, env(safe-area-inset-bottom)); padding-bottom: var(--material-safe-bottom, env(safe-area-inset-bottom));
translate: 0 100%; translate: 0 100%;
transition-property: translate, display; transition-property: translate;
transition-duration: var(--md-sys-motion-effects-default-duration); transition-duration: var(--md-sys-motion-effects-default-duration);
transition-timing-function: var(--md-sys-motion-easing-emphasized-accelerate); transition-timing-function: var(--md-sys-motion-easing-emphasized-accelerate);
transition-behavior: allow-discrete;
} }
[data-md-bottom-sheet][data-md-open] > [data-md-bottom-sheet-panel] { [data-md-bottom-sheet][data-md-open] > [data-md-bottom-sheet-panel] {
@@ -107,14 +109,14 @@
spring, independent of the translate that opens and closes the sheet. */ spring, independent of the translate that opens and closes the sheet. */
[data-md-bottom-sheet-panel][data-md-preset] { [data-md-bottom-sheet-panel][data-md-preset] {
height: var(--sheet-max-height); height: var(--sheet-max-height);
transition-property: translate, height, display; transition-property: translate, height;
transition-duration: var(--md-sys-motion-effects-default-duration), var(--md-sys-motion-spatial-default-duration), var(--md-sys-motion-effects-default-duration); transition-duration: var(--md-sys-motion-effects-default-duration), var(--md-sys-motion-spatial-default-duration);
transition-timing-function: var(--md-sys-motion-easing-emphasized-accelerate), var(--md-sys-motion-spatial-default), var(--md-sys-motion-easing-emphasized-accelerate); transition-timing-function: var(--md-sys-motion-easing-emphasized-accelerate), var(--md-sys-motion-spatial-default);
} }
[data-md-bottom-sheet][data-md-open] > [data-md-bottom-sheet-panel][data-md-preset] { [data-md-bottom-sheet][data-md-open] > [data-md-bottom-sheet-panel][data-md-preset] {
transition-duration: var(--md-sys-motion-spatial-default-duration), var(--md-sys-motion-spatial-default-duration), var(--md-sys-motion-spatial-default-duration); transition-duration: var(--md-sys-motion-spatial-default-duration), var(--md-sys-motion-spatial-default-duration);
transition-timing-function: var(--md-sys-motion-easing-emphasized-decelerate), var(--md-sys-motion-spatial-default), var(--md-sys-motion-easing-emphasized-decelerate); transition-timing-function: var(--md-sys-motion-easing-emphasized-decelerate), var(--md-sys-motion-spatial-default);
} }
[data-md-bottom-sheet-handle] { [data-md-bottom-sheet-handle] {
+8 -6
View File
@@ -18,9 +18,12 @@
* 400px cap, 24dp start/end padding, a large corner on the inner edge only — from the specs * 400px cap, 24dp start/end padding, a large corner on the inner edge only — from the specs
* table. It enters on the emphasized-decelerate easing rather than a spring, because a sheet * table. It enters on the emphasized-decelerate easing rather than a spring, because a sheet
* anchored to an edge that overshot would open a gap, and leaves on emphasized accelerate: the * anchored to an edge that overshot would open a gap, and leaves on emphasized accelerate: the
* view keeps `x-show`, so `@starting-style` gives the entry its start and `allow-discrete` holds * view keeps `x-show`, so `@starting-style` gives the entry its start and the view's `x-transition`
* `display` through the exit, whose timing comes from the closed state's own rule (a transition * holds `display` through the exit, whose timing comes from the closed state's own rule (a
* takes the after-change style's). Reduced motion zeroes both duration tokens (tokens/motion.css). * transition takes the after-change style's). Not `allow-discrete` on `display`: Firefox does not
* transition `display`, and in the other engines it would hold a second time after Alpine's hold.
* Alpine holds for the first `transition-duration` listed, so each exit's longest transition is
* listed first. Reduced motion zeroes both duration tokens (tokens/motion.css).
* Below `expanded` it slides, from whichever edge `data-md-side` names in the document's direction; * Below `expanded` it slides, from whichever edge `data-md-side` names in the document's direction;
* once `standard` makes it co-planar it only fades (an in-flow box does not need to travel). Every * once `standard` makes it co-planar it only fades (an in-flow box does not need to travel). Every
* state rule matches the sheet and scrim as the root's children, so a sheet nested in an open one * state rule matches the sheet and scrim as the root's children, so a sheet nested in an open one
@@ -84,10 +87,9 @@
color: var(--md-sys-color-on-surface); color: var(--md-sys-color-on-surface);
box-shadow: var(--md-sys-elevation-1); box-shadow: var(--md-sys-elevation-1);
translate: var(--sheet-offset) 0; translate: var(--sheet-offset) 0;
transition-property: translate, display; transition-property: translate;
transition-duration: var(--md-sys-motion-effects-default-duration); transition-duration: var(--md-sys-motion-effects-default-duration);
transition-timing-function: var(--md-sys-motion-easing-emphasized-accelerate); transition-timing-function: var(--md-sys-motion-easing-emphasized-accelerate);
transition-behavior: allow-discrete;
} }
[data-md-drawer-sheet][data-md-side='end'] { [data-md-drawer-sheet][data-md-side='end'] {
@@ -167,7 +169,7 @@
background-color: var(--md-sys-color-surface); background-color: var(--md-sys-color-surface);
box-shadow: none; box-shadow: none;
opacity: 0; opacity: 0;
transition-property: opacity, display; transition-property: opacity;
transition-duration: var(--md-sys-motion-effects-default-duration); transition-duration: var(--md-sys-motion-effects-default-duration);
transition-timing-function: var(--md-sys-motion-easing-emphasized-accelerate); transition-timing-function: var(--md-sys-motion-easing-emphasized-accelerate);
} }
+15 -4
View File
@@ -56,10 +56,9 @@
inset: 0; inset: 0;
z-index: -1; z-index: -1;
background-color: color-mix(in srgb, var(--md-sys-color-scrim) 32%, transparent); background-color: color-mix(in srgb, var(--md-sys-color-scrim) 32%, transparent);
transition-property: opacity, display; transition-property: opacity;
transition-duration: var(--md-sys-motion-effects-fast-duration); transition-duration: var(--md-sys-motion-effects-fast-duration);
transition-timing-function: var(--md-sys-motion-effects-fast); transition-timing-function: var(--md-sys-motion-effects-fast);
transition-behavior: allow-discrete;
} }
@starting-style { @starting-style {
@@ -68,6 +67,12 @@
} }
} }
/* Closing (or turning full screen), the scrim fades back out while the view's `x-transition`
holds its `display`: not `allow-discrete`, which Firefox does not honour for `display`. */
[data-md-search]:is(:not([data-md-open]), [data-md-full-screen]) > [data-md-search-scrim] {
opacity: 0;
}
[data-md-search-bar] { [data-md-search-bar] {
position: relative; position: relative;
z-index: 1; z-index: 1;
@@ -201,10 +206,9 @@
background-color: var(--md-sys-color-surface-container-high); background-color: var(--md-sys-color-surface-container-high);
box-shadow: var(--md-sys-elevation-3); box-shadow: var(--md-sys-elevation-3);
transform-origin: top; transform-origin: top;
transition-property: opacity, scale, display; transition-property: opacity, scale;
transition-duration: var(--md-sys-motion-spatial-fast-duration); transition-duration: var(--md-sys-motion-spatial-fast-duration);
transition-timing-function: var(--md-sys-motion-spatial-fast); transition-timing-function: var(--md-sys-motion-spatial-fast);
transition-behavior: allow-discrete;
} }
@starting-style { @starting-style {
@@ -214,6 +218,13 @@
} }
} }
/* Closing, the view goes back the way it came, into the bar, while its `x-transition` holds
`display` for the same duration. */
[data-md-search]:not([data-md-open]) > [data-md-search-view] {
opacity: 0;
scale: 1 0.9;
}
/* M3: the docked container is at least 240px tall — once there is something in it to be tall /* M3: the docked container is at least 240px tall — once there is something in it to be tall
about; a search with nothing to show stays the height of its bar. */ about; a search with nothing to show stays the height of its bar. */
[data-md-search-view]:has([data-md-search-results], [data-md-search-suggestions]) { [data-md-search-view]:has([data-md-search-results], [data-md-search-suggestions]) {
@@ -104,8 +104,9 @@
@if ($standard) data-md-standard @endif @if ($standard) data-md-standard @endif
> >
@unless ($standard) @unless ($standard)
{{-- Alpine's CSS transition holds the scrim for its fade, as in drawer.blade.php. --}} {{-- `md-transition` turns on Alpine's CSS transition, which holds the scrim and the panel
<div data-md-bottom-sheet-scrim x-cloak x-show="open" x-transition:enter="md-scrim-transition" x-transition:leave="md-scrim-transition" x-on:click="close()" aria-hidden="true"></div> displayed through their exit, as in drawer.blade.php. --}}
<div data-md-bottom-sheet-scrim x-cloak x-show="open" x-transition:enter="md-transition" x-transition:leave="md-transition" x-on:click="close()" aria-hidden="true"></div>
@endunless @endunless
@if ($stops !== []) @if ($stops !== [])
@@ -117,6 +118,8 @@
<section <section
x-cloak x-cloak
x-show="open" x-show="open"
x-transition:enter="md-transition"
x-transition:leave="md-transition"
x-ref="sheet" x-ref="sheet"
@unless ($standard) x-trap.inert.noscroll="open" @endunless @unless ($standard) x-trap.inert.noscroll="open" @endunless
x-bind:style="sheetStyle" x-bind:style="sheetStyle"
+8 -5
View File
@@ -93,15 +93,18 @@
data-md-drawer data-md-drawer
@if ($standard) data-md-standard @endif @if ($standard) data-md-standard @endif
> >
{{-- The class names only turn on Alpine's CSS transition: it keeps the scrim displayed for the {{-- `md-transition` is a class name only to turn on Alpine's CSS transition: `x-show` then keeps
computed transition-duration (drawer.css's effects token) before hiding it, because Firefox the scrim and the sheet displayed for their computed transition-duration (drawer.css's
does not transition `display`, even with `allow-discrete`. Both stages, so reopening during tokens) before hiding them, so they fade and slide out rather than vanish Firefox does not
the fade cancels the pending hide. --}} transition `display`, even with `allow-discrete`. Both stages, so reopening during the exit
<div data-md-drawer-scrim x-cloak x-show="open" x-transition:enter="md-scrim-transition" x-transition:leave="md-scrim-transition" @if (! $withoutBackdropClose) x-on:click="close()" @endif aria-hidden="true"></div> cancels the pending hide. Nothing styles the class. --}}
<div data-md-drawer-scrim x-cloak x-show="open" x-transition:enter="md-transition" x-transition:leave="md-transition" @if (! $withoutBackdropClose) x-on:click="close()" @endif aria-hidden="true"></div>
<aside <aside
x-cloak x-cloak
x-show="open" x-show="open"
x-transition:enter="md-transition"
x-transition:leave="md-transition"
x-trap.inert.noscroll="open && ! wide" x-trap.inert.noscroll="open && ! wide"
x-bind:role="wide ? 'region' : 'dialog'" x-bind:role="wide ? 'region' : 'dialog'"
x-bind:aria-modal="wide ? null : 'true'" x-bind:aria-modal="wide ? null : 'true'"
+5 -1
View File
@@ -66,7 +66,9 @@
data-md-trigger="{{ $trigger }}" data-md-trigger="{{ $trigger }}"
{{ $attributes->only(['class', 'style', 'wire:key']) }} {{ $attributes->only(['class', 'style', 'wire:key']) }}
> >
<div data-md-search-scrim x-cloak x-show="open && ! fullScreen" x-on:pointerdown="close()" aria-hidden="true"></div> {{-- `md-transition` turns on Alpine's CSS transition, which holds the scrim and the view
displayed while they fade out (search.css): Firefox does not transition `display`. --}}
<div data-md-search-scrim x-cloak x-show="open && ! fullScreen" x-transition:enter="md-transition" x-transition:leave="md-transition" x-on:pointerdown="close()" aria-hidden="true"></div>
@if ($trigger === 'icon') @if ($trigger === 'icon')
<button <button
@@ -134,6 +136,8 @@
data-md-search-view data-md-search-view
x-cloak x-cloak
x-show="open" x-show="open"
x-transition:enter="md-transition"
x-transition:leave="md-transition"
x-on:keydown.arrow-down.prevent="step(1)" x-on:keydown.arrow-down.prevent="step(1)"
x-on:keydown.arrow-up.prevent="step(-1)" x-on:keydown.arrow-up.prevent="step(-1)"
x-on:click="choose($event)" x-on:click="choose($event)"
+62
View File
@@ -635,6 +635,68 @@ it('fades the bottom sheet\'s scrim out on close, rather than making it vanish',
$page->assertScript("getComputedStyle({$scrim}).display === 'none'"); $page->assertScript("getComputedStyle({$scrim}).display === 'none'");
}); });
it('slides the side sheet out on close, rather than making it vanish', function () {
$sheet = "document.querySelector('#containment aside[role=\"dialog\"]')";
$scrim = "{$sheet}.parentElement.querySelector(':scope > [data-md-drawer-scrim]')";
$page = containment()
->click('#containment button:has-text("Side sheet")')
->assertScript("getComputedStyle({$sheet}).display !== 'none'")
->assertScript("Math.abs(parseFloat(getComputedStyle({$sheet}).translate)) < 0.5");
// Sampled in the page, in the same round trip as the close, as the scrim's fade is above: the
// sheet must be caught still displayed and part of the way to its closed offset (one sheet
// width past its edge), not gone at once — which is what Firefox showed while the exit leaned
// on `allow-discrete` holding `display`.
$midSlide = $page->script(<<<JS
(async () => {
const width = {$sheet}.getBoundingClientRect().width
{$scrim}.click()
for (let i = 0; i < 60; i++) {
const style = getComputedStyle({$sheet})
const offset = Math.abs(parseFloat(style.translate) || 0)
if (style.display !== 'none' && offset > 1 && offset < width - 1) return true
await new Promise((resolve) => setTimeout(resolve, 5))
}
return false
})()
JS);
expect($midSlide)->toBeTrue();
$page->assertScript("getComputedStyle({$sheet}).display === 'none'");
});
it('slides the bottom sheet down on close, rather than making it vanish', function () {
$sheet = "document.querySelector('#containment section[role=\"dialog\"]')";
$scrim = "{$sheet}.parentElement.querySelector(':scope > [data-md-bottom-sheet-scrim]')";
$offset = "(parseFloat(getComputedStyle({$sheet}).translate.split(' ')[1]) || 0)";
$page = containment()
->click('#containment button:has(> span:text-is("Bottom sheet"))')
->assertScript("getComputedStyle({$sheet}).display !== 'none'")
->assertScript("Math.abs({$offset}) < 0.5");
$midSlide = $page->script(<<<JS
(async () => {
const height = {$sheet}.getBoundingClientRect().height
{$scrim}.click()
for (let i = 0; i < 60; i++) {
const offset = {$offset}
if (getComputedStyle({$sheet}).display !== 'none' && offset > 1 && offset < height - 1) return true
await new Promise((resolve) => setTimeout(resolve, 5))
}
return false
})()
JS);
expect($midSlide)->toBeTrue();
$page->assertScript("getComputedStyle({$sheet}).display === 'none'");
});
it('slides the side sheet in from its own edge in a right-to-left page', function () { it('slides the side sheet in from its own edge in a right-to-left page', function () {
Route::middleware('web')->get('/drawer-rtl-probe', fn () => Blade::render(<<<'BLADE' Route::middleware('web')->get('/drawer-rtl-probe', fn () => Blade::render(<<<'BLADE'
<!DOCTYPE html> <!DOCTYPE html>
+49
View File
@@ -175,6 +175,55 @@ it('says so when nothing matches, and closes on a press outside or a chosen resu
->assertScript("getComputedStyle({$view}).display === 'none'"); ->assertScript("getComputedStyle({$view}).display === 'none'");
}); });
/**
* Presses the open docked search's scrim and samples, in the page and in the same round trip,
* whether `$expression` (a number) was ever caught strictly between `$from` and `$to` while the
* element was still displayed: the exit ran, rather than the element vanishing at once.
*/
function searchCloseSample(string $element, string $expression): string
{
return <<<JS
(async () => {
const root = document.querySelector('[data-md-search]:has(#find)')
root.querySelector('[data-md-search-scrim]').dispatchEvent(new PointerEvent('pointerdown', { bubbles: true }))
for (let i = 0; i < 80; i++) {
const element = root.querySelector('{$element}')
const value = {$expression}
if (getComputedStyle(element).display !== 'none' && value > 0.02 && value < 0.98) return true
await new Promise((resolve) => setTimeout(resolve, 5))
}
return false
})()
JS;
}
it('fades the docked search\'s scrim out on close, rather than making it vanish', function () {
$root = "document.querySelector('[data-md-search]:has(#find)')";
$page = pickProbe()
->click('#find')
// Displayed as well as opaque: until the first frame of its entry the scrim is still
// `display: none` at the open state's full opacity.
->assertScript("(({ display, opacity }) => display !== 'none' && opacity === '1')(getComputedStyle({$root}.querySelector('[data-md-search-scrim]')))");
expect($page->script(searchCloseSample('[data-md-search-scrim]', 'parseFloat(getComputedStyle(element).opacity)')))->toBeTrue();
$page->assertScript("getComputedStyle({$root}.querySelector('[data-md-search-scrim]')).display === 'none'");
});
it('closes the docked search view back into its bar, rather than making it vanish', function () {
$view = "document.querySelector('#find-view')";
$page = pickProbe()
->click('#find')
->assertScript("getComputedStyle({$view}).display !== 'none' && getComputedStyle({$view}).opacity === '1'");
expect($page->script(searchCloseSample('[data-md-search-view]', 'parseFloat(getComputedStyle(element).opacity)')))->toBeTrue();
$page->assertScript("getComputedStyle({$view}).display === 'none'");
});
it('takes the whole screen on a compact window, with a back arrow', function () { it('takes the whole screen on a compact window, with a back arrow', function () {
$page = pickProbe()->resize(400, 800); $page = pickProbe()->resize(400, 800);
+8 -2
View File
@@ -251,15 +251,21 @@ it('is M3\'s standard side sheet from expanded, and the modal one below', functi
it('slides a side sheet out as it slid in, from its own edge in either direction, and fades its scrim both ways', function () { it('slides a side sheet out as it slid in, from its own edge in either direction, and fades its scrim both ways', function () {
$css = ComponentStylesheet::read('drawer'); $css = ComponentStylesheet::read('drawer');
// Alpine's CSS transition holds `display` through the exit (the view's `x-transition`), not
// `allow-discrete`, which Firefox does not honour for `display`.
expect($css->declarations('[data-md-drawer-sheet]')) expect($css->declarations('[data-md-drawer-sheet]'))
->toHaveKey('translate', 'var(--sheet-offset) 0') ->toHaveKey('translate', 'var(--sheet-offset) 0')
->toHaveKey('transition-behavior', 'allow-discrete') ->toHaveKey('transition-property', 'translate')
->not->toHaveKey('transition-behavior')
->not->toHaveKey('opacity') ->not->toHaveKey('opacity')
->and($css->declarations("[data-md-drawer-sheet][data-md-side='end']:is([dir='rtl'], [dir='rtl'] *)"))->toBe(['--sheet-offset' => '-100%']) ->and($css->declarations("[data-md-drawer-sheet][data-md-side='end']:is([dir='rtl'], [dir='rtl'] *)"))->toBe(['--sheet-offset' => '-100%'])
->and($css->declarations("[data-md-drawer-sheet][data-md-side='start']:is([dir='rtl'], [dir='rtl'] *)"))->toBe(['--sheet-offset' => '100%']) ->and($css->declarations("[data-md-drawer-sheet][data-md-side='start']:is([dir='rtl'], [dir='rtl'] *)"))->toBe(['--sheet-offset' => '100%'])
->and($css->declarations('[data-md-drawer][data-md-open] > [data-md-drawer-sheet]', ['@starting-style']))->toBe(['translate' => 'var(--sheet-offset) 0']) ->and($css->declarations('[data-md-drawer][data-md-open] > [data-md-drawer-sheet]', ['@starting-style']))->toBe(['translate' => 'var(--sheet-offset) 0'])
->and($css->declarations('[data-md-drawer-scrim]'))->toHaveKey('opacity', '0') ->and($css->declarations('[data-md-drawer-scrim]'))->toHaveKey('opacity', '0')
->and($css->declarations('[data-md-drawer][data-md-open] > [data-md-drawer-scrim]'))->toBe(['opacity' => '1']); ->and($css->declarations('[data-md-drawer][data-md-open] > [data-md-drawer-scrim]'))->toBe(['opacity' => '1'])
->and((string) $this->blade('<x-drawer title="Filters">Body</x-drawer>'))
->toMatch('/<div data-md-drawer-scrim x-cloak x-show="open" x-transition:enter="md-transition" x-transition:leave="md-transition"/')
->toMatch('/<aside\s+x-cloak\s+x-show="open"\s+x-transition:enter="md-transition"\s+x-transition:leave="md-transition"/');
}); });
it('draws the drawer from a stylesheet imported from the containment block, with the pane prop gone', function () { it('draws the drawer from a stylesheet imported from the containment block, with the pane prop gone', function () {