Skip to content

fix: improve each block with animate #9839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/twelve-dragons-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: improve each block with animate
1 change: 1 addition & 0 deletions packages/svelte/src/internal/client/each.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ function reconcile_tracked_array(
a = sources[i];
if (pos === MOVED_BLOCK && a !== LIS_BLOCK) {
block = b_blocks[b_end];
item = array[b_end];
update_each_item_block(block, item, b_end, flags);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { flushSync } from 'svelte';
import { ok, test } from '../../test';

export default test({
async test({ assert, target, window }) {
const button = target.querySelector('button');
ok(button);

assert.htmlEqual(
target.innerHTML,
`
<button>Shuffle</button><div class="list"><label><input type="checkbox">
write
some
docs</label><label><input type="checkbox">
start
writing
JSConf
talk</label><label><input type="checkbox">
buy
some
milk</label><label><input type="checkbox">
mow
the
lawn</label><label><input type="checkbox">
feed
the
turtle</label><label><input type="checkbox">
fix
some
bugs</label></div>`
);

flushSync(() => {
button.click();
});

assert.htmlEqual(
target.innerHTML,
`
<button>Shuffle</button><div class="list"><label><input type="checkbox">
fix
some
bugs</label><label><input type="checkbox">
feed
the
turtle</label><label><input type="checkbox">
mow
the
lawn</label><label><input type="checkbox">
buy
some
milk</label><label><input type="checkbox">
start
writing
JSConf
talk</label><label><input type="checkbox">
write
some
docs</label></div>`
);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<script>
import { flip } from 'svelte/animate';

let todos = [
{ id: 1, done: false, description: 'write some docs' },
{ id: 2, done: false, description: 'start writing JSConf talk' },
{ id: 3, done: true, description: 'buy some milk' },
{ id: 4, done: false, description: 'mow the lawn' },
{ id: 5, done: false, description: 'feed the turtle' },
{ id: 6, done: false, description: 'fix some bugs' }
];

function update() {
todos = Array.from(todos).reverse();
}
</script>

<button on:click={update}>Shuffle</button>

<div class="list">
{#each todos as todo (todo.id)}
<label animate:flip>
<input type="checkbox" bind:checked={todo.done} />
{todo.description}
</label>
{/each}
</div>