mirror of https://github.com/sveltejs/svelte
fix: make onintrostart respect delay parameter (#17567)
* fix: make onintrostart respect delay parameter Fixes #14009 The onintrostart event now fires after the delay period completes, rather than immediately when the transition is initiated. This ensures that the event accurately reflects when the intro animation actually starts. Changes: - Added on_start callback parameter to animate() function - Dispatch introstart event after delay animation finishes - Handle edge case where duration is 0 but delay > 0 * fix: format code with prettier * add (failing) tests * fix * changeset * missed a spot * fix --------- Co-authored-by: Miner <miner@example.com> Co-authored-by: Rich Harris <rich.harris@vercel.com>pull/17575/head
parent
06e6ef83b8
commit
16fec7207a
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: fire introstart/outrostart events after delay, if specified
|
||||
@ -0,0 +1,32 @@
|
||||
import { flushSync } from '../../../../src/index-client.js';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
test({ assert, raf, target, logs }) {
|
||||
const [btn] = target.querySelectorAll('button');
|
||||
|
||||
// in
|
||||
flushSync(() => btn.click());
|
||||
assert.deepEqual(logs, []);
|
||||
raf.tick(1);
|
||||
assert.deepEqual(logs, []);
|
||||
|
||||
raf.tick(100);
|
||||
assert.deepEqual(logs, ['introstart']);
|
||||
|
||||
raf.tick(200);
|
||||
assert.deepEqual(logs, ['introstart', 'introend']);
|
||||
|
||||
// out
|
||||
flushSync(() => btn.click());
|
||||
assert.deepEqual(logs, ['introstart', 'introend']);
|
||||
raf.tick(201);
|
||||
assert.deepEqual(logs, ['introstart', 'introend']);
|
||||
|
||||
raf.tick(300);
|
||||
assert.deepEqual(logs, ['introstart', 'introend', 'outrostart']);
|
||||
|
||||
raf.tick(400);
|
||||
assert.deepEqual(logs, ['introstart', 'introend', 'outrostart', 'outroend']);
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,23 @@
|
||||
<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
|
||||
onintrostart={() => console.log('introstart')}
|
||||
onintroend={() => console.log('introend')}
|
||||
onoutrostart={() => console.log('outrostart')}
|
||||
onoutroend={() => console.log('outroend')}
|
||||
>delayed fade</p>
|
||||
{/if}
|
||||
@ -0,0 +1,32 @@
|
||||
import { flushSync } from '../../../../src/index-client.js';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
test({ assert, raf, target, logs }) {
|
||||
const [btn] = target.querySelectorAll('button');
|
||||
|
||||
// in
|
||||
flushSync(() => btn.click());
|
||||
assert.deepEqual(logs, []);
|
||||
raf.tick(1);
|
||||
assert.deepEqual(logs, []);
|
||||
|
||||
raf.tick(100);
|
||||
assert.deepEqual(logs, ['introstart']);
|
||||
|
||||
raf.tick(200);
|
||||
assert.deepEqual(logs, ['introstart', 'introend']);
|
||||
|
||||
// out
|
||||
flushSync(() => btn.click());
|
||||
assert.deepEqual(logs, ['introstart', 'introend']);
|
||||
raf.tick(201);
|
||||
assert.deepEqual(logs, ['introstart', 'introend']);
|
||||
|
||||
raf.tick(300);
|
||||
assert.deepEqual(logs, ['introstart', 'introend', 'outrostart']);
|
||||
|
||||
raf.tick(400);
|
||||
assert.deepEqual(logs, ['introstart', 'introend', 'outrostart', 'outroend']);
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,23 @@
|
||||
<script>
|
||||
function fade(node) {
|
||||
return {
|
||||
delay: 100,
|
||||
duration: 100,
|
||||
tick: (t) => node.style.opacity = t
|
||||
};
|
||||
}
|
||||
|
||||
let visible = $state(false);
|
||||
</script>
|
||||
|
||||
<button onclick={() => (visible = !visible)}>toggle</button>
|
||||
|
||||
{#if visible}
|
||||
<p
|
||||
transition:fade
|
||||
onintrostart={() => console.log('introstart')}
|
||||
onintroend={() => console.log('introend')}
|
||||
onoutrostart={() => console.log('outrostart')}
|
||||
onoutroend={() => console.log('outroend')}
|
||||
>delayed fade</p>
|
||||
{/if}
|
||||
Loading…
Reference in new issue