-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix] Local transitions from #key blocks (#7286)
* fix: Local transitions from #key blocks When adding `|local` to a transition inside a {#key} block, only the outro was triggered not the intro. This PR fixes #5950 * add test case Co-authored-by: tanhauhau <[email protected]>
- Loading branch information
Showing
3 changed files
with
58 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
test/runtime/samples/key-block-transition-local/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
export default { | ||
props: { | ||
x: false, | ||
y: 1 | ||
}, | ||
|
||
test({ assert, component, target, raf }) { | ||
component.x = true; | ||
|
||
let div = target.querySelector('div'); | ||
assert.equal(div.foo, undefined); | ||
|
||
// play both in and out transition when changed with `{#key}` | ||
component.y = 2; | ||
assert.htmlEqual(target.innerHTML, '<div></div><div></div>'); | ||
const [leaving, incoming] = target.querySelectorAll('div'); | ||
|
||
raf.tick(50); | ||
assert.equal(leaving.foo, 0.5); | ||
assert.equal(incoming.foo, 0.5); | ||
|
||
raf.tick(100); | ||
assert.htmlEqual(target.innerHTML, '<div></div>'); | ||
assert.equal(leaving.foo, 0); | ||
assert.equal(incoming.foo, 1); | ||
|
||
// do not play out transition when removed by `{#if}` | ||
component.x = false; | ||
assert.htmlEqual(target.innerHTML, ''); | ||
|
||
// do not play in transition when added back with `{#if}` | ||
component.x = true; | ||
assert.htmlEqual(target.innerHTML, '<div></div>'); | ||
div = target.querySelector('div'); | ||
assert.equal(div.foo, undefined); | ||
} | ||
}; |
19 changes: 19 additions & 0 deletions
19
test/runtime/samples/key-block-transition-local/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<script> | ||
export let x; | ||
export let y; | ||
function foo(node, _params) { | ||
return { | ||
duration: 100, | ||
tick: t => { | ||
node.foo = t; | ||
} | ||
}; | ||
} | ||
</script> | ||
|
||
{#if x} | ||
{#key y} | ||
<div transition:foo|local></div> | ||
{/key} | ||
{/if} |