mirror of https://github.com/sveltejs/svelte
breaking: play transitions on `mount` by default (#12351)
* breaking: play transitions on `mount` by default closes #11280 * only prevent transitions when the component is invalidated --------- Co-authored-by: Rich Harris <rich.harris@vercel.com>pull/12353/head
parent
e8c3729fc9
commit
ba93e5fce3
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
breaking: play transitions on `mount` by default
|
@ -0,0 +1,5 @@
|
||||
<script>
|
||||
import { fade } from 'svelte/transition';
|
||||
</script>
|
||||
|
||||
<div in:fade|global={{ duration: 100 }}>DIV</div>
|
@ -0,0 +1,21 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { ok, test } from '../../test';
|
||||
|
||||
export default test({
|
||||
async test({ assert, target, raf }) {
|
||||
const [btn1, btn2] = target.querySelectorAll('button');
|
||||
const div = target.querySelector('div');
|
||||
ok(div);
|
||||
|
||||
btn1.click();
|
||||
flushSync();
|
||||
assert.htmlEqual(div.innerHTML, `<div style="opacity: 0;">DIV</div>`);
|
||||
|
||||
raf.tick(100);
|
||||
assert.htmlEqual(div.innerHTML, `<div style="">DIV</div>`);
|
||||
|
||||
btn2.click();
|
||||
flushSync();
|
||||
assert.htmlEqual(div.innerHTML, `<div>DIV</div>`);
|
||||
}
|
||||
});
|
@ -0,0 +1,21 @@
|
||||
<script>
|
||||
import { mount, unmount } from 'svelte';
|
||||
import Component from './Component.svelte';
|
||||
|
||||
let el;
|
||||
let instance;
|
||||
|
||||
function intro(animate) {
|
||||
if (instance) unmount(instance);
|
||||
|
||||
instance = mount(Component, {
|
||||
target: el,
|
||||
intro: animate
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<div bind:this={el}></div>
|
||||
|
||||
<button onclick={() => intro()}>mount with intro transition</button>
|
||||
<button onclick={() => intro(false)}>mount without intro transition</button>
|
Loading…
Reference in new issue