mirror of https://github.com/sveltejs/svelte
fix: ensure transitions are applied to nested elements (#14080)
parent
0ed914b2e5
commit
58b1540ddc
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: ensure transitions are applied to nested elements
|
@ -0,0 +1,14 @@
|
||||
/** @import { AST } from '#compiler' */
|
||||
/** @import { Context } from '../types' */
|
||||
|
||||
import { mark_subtree_dynamic } from './shared/fragment.js';
|
||||
|
||||
/**
|
||||
* @param {AST.TransitionDirective} node
|
||||
* @param {Context} context
|
||||
*/
|
||||
export function TransitionDirective(node, context) {
|
||||
mark_subtree_dynamic(context.path);
|
||||
|
||||
context.next();
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
import { flushSync } from '../../../../src/index-client.js';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
async test({ assert, raf, target }) {
|
||||
assert.htmlEqual(target.innerHTML, '<button>Toggle</button><div><span>123</span></div>');
|
||||
|
||||
const btn1 = target.querySelector('button');
|
||||
btn1?.click();
|
||||
flushSync();
|
||||
raf.tick(250);
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
'<button>Toggle</button><div><span style="opacity: 0.5;">123</span></div>'
|
||||
);
|
||||
|
||||
flushSync();
|
||||
raf.tick(500);
|
||||
|
||||
assert.htmlEqual(target.innerHTML, '<button>Toggle</button>');
|
||||
}
|
||||
});
|
@ -0,0 +1,18 @@
|
||||
<script>
|
||||
function fade(_) {
|
||||
return {
|
||||
duration: 500,
|
||||
css: t => `opacity: ${t}`,
|
||||
}
|
||||
}
|
||||
|
||||
let visible = $state(true);
|
||||
</script>
|
||||
|
||||
<button onclick={() => visible = !visible}>Toggle</button>
|
||||
|
||||
{#if visible}
|
||||
<div>
|
||||
<span transition:fade>123</span>
|
||||
</div>
|
||||
{/if}
|
Loading…
Reference in new issue