mirror of https://github.com/sveltejs/svelte
fix: properly delay intro transitions (#12389)
* fix: properly delay intro transitions WAAPI applies the styles of a delayed animation only when that animation starts. In the case of fade-in transitions that means the element is visible, then goes invisible and fades in. Fix that by never applying a delay on intro transitions, instead add keyframes of the initial state for the duration of the delay. Fixes #10876 * fix bug, make test pass * make test more selfcontained, test outro delay aswell and add functionality for that in animation-helpers * lint --------- Co-authored-by: Rich Harris <rich.harris@vercel.com>pull/12395/head
parent
f846cb4833
commit
277370a79d
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: properly delay intro transitions
|
@ -0,0 +1,48 @@
|
||||
import { flushSync } from '../../../../src/index-client.js';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
test({ assert, raf, target }) {
|
||||
const btn = target.querySelector('button');
|
||||
|
||||
// in
|
||||
btn?.click();
|
||||
flushSync();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
'<button>toggle</button><p style="opacity: 0;">delayed fade</p>'
|
||||
);
|
||||
raf.tick(1);
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
'<button>toggle</button><p style="opacity: 0;">delayed fade</p>'
|
||||
);
|
||||
|
||||
raf.tick(99);
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
'<button>toggle</button><p style="opacity: 0;">delayed fade</p>'
|
||||
);
|
||||
|
||||
raf.tick(150);
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
'<button>toggle</button><p style="opacity: 0.5;">delayed fade</p>'
|
||||
);
|
||||
|
||||
raf.tick(200);
|
||||
assert.htmlEqual(target.innerHTML, '<button>toggle</button><p style="">delayed fade</p>');
|
||||
|
||||
// out
|
||||
btn?.click();
|
||||
flushSync();
|
||||
raf.tick(275);
|
||||
assert.htmlEqual(target.innerHTML, '<button>toggle</button><p style="">delayed fade</p>');
|
||||
|
||||
raf.tick(350);
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
'<button>toggle</button><p style="opacity: 0.5;">delayed fade</p>'
|
||||
);
|
||||
}
|
||||
});
|
@ -0,0 +1,17 @@
|
||||
<script>
|
||||
function fade(_) {
|
||||
return {
|
||||
delay: 100,
|
||||
duration: 100,
|
||||
css: (t) => `opacity: ${t}`
|
||||
};
|
||||
}
|
||||
|
||||
let visible = $state(false);
|
||||
</script>
|
||||
|
||||
<button onclick={() => (visible = !visible)}>toggle</button>
|
||||
|
||||
{#if visible}
|
||||
<p transition:fade>delayed fade</p>
|
||||
{/if}
|
Loading…
Reference in new issue