mirror of https://github.com/sveltejs/svelte
Merge pull request #3443 from sveltejs/gh-2569
update context if event handler uses index in keyed each blockpull/3451/head
commit
143125ecef
@ -0,0 +1,18 @@
|
||||
export default {
|
||||
html: `
|
||||
<button>remove</button>
|
||||
<button>remove</button>
|
||||
<button>remove</button>
|
||||
`,
|
||||
|
||||
async test({ assert, target, window }) {
|
||||
const click = new window.MouseEvent('click');
|
||||
|
||||
await target.querySelectorAll('button')[1].dispatchEvent(click);
|
||||
await target.querySelectorAll('button')[1].dispatchEvent(click);
|
||||
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<button>remove</button>
|
||||
`);
|
||||
}
|
||||
};
|
@ -0,0 +1,16 @@
|
||||
<script>
|
||||
let list = ["a", "b", "c"];
|
||||
|
||||
const remove = index => {
|
||||
list.splice(index, 1);
|
||||
list = list;
|
||||
};
|
||||
</script>
|
||||
|
||||
{#each list as value, index (value)}
|
||||
{#if value}
|
||||
<button on:click="{e => remove(index)}">
|
||||
remove
|
||||
</button>
|
||||
{/if}
|
||||
{/each}
|
Loading…
Reference in new issue