-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
An element that uses the animate directive must be the immediate child of a keyed each block #7209
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
Comments
@matths I found a solution after facing the same: "What you have is an indexed each block, which won't work. A keyed each block looks like this. (preferably with a proper key)" You can then use index to set an id on the element you're creating https://stackoverflow.com/questions/59497908/animations-in-svelte-component |
@barcovanrhijn I'll have a look at your suggestion soon and give you feedback afterwards. Thanks for the comment. |
I just ran into the same problem. Any ideas on how we should move forward? |
@matths , <section use:dndzone={{ items: $store, flipDurationMs }} on:consider={handleSort} on:finalize={handleSort}>
{#each $store as item (item.id)}
<div id={item.id} animate:flip={{ duration: flipDurationMs }}>...</div>
{/each}
</section> Error: Any ideas how to prevent this, I got the same issue trying to use index. |
Any news ? |
This is a major pain point for users of Svelte Headless Table as well. The main sell is that Svelte Headless Table is truly headless so all of Svelte's native directives should work out of the box. However, we use a <tbody {...$tableBodyAttrs}>
{#each $rows as row (row.id)}
<Subscribe rowAttrs={row.attrs()} let:rowAttrs>
<tr animate:flip={{duration: 200}} {...rowAttrs}>
{#each row.cells as cell (cell.id)}
<Subscribe attrs={cell.attrs()} let:attrs>
<td {...attrs}>
<Render of={cell.render()} />
</td>
</Subscribe>
{/each}
</tr>
</Subscribe>
{/each}
</tbody> Without support for It would be nice if |
I am experiencing same issue. Did anyone find a possible solution? |
Same issue. Simple letter adding to a grid, without the animate, simple to add another letter once you've exhausted your initial array of letters: repl here But if you add animate, you have to change the syntax of the #each, and once you hit the end of your list it fails to add another letter (I assume because n is no longer unique?) |
+1 |
Is there no way around this? It means I have to update the parent of the child widget I want the state to update in a list, so the entire parent container tree has to be rerendered, because I can't move my state contained in the direct child |
+1 |
@3daddict I did not find a solution and moved away from Svelte. An issue like this tells me Svelte is not ready for my use case. |
Why not use your component inside a div 👀 |
That's how I fixed it but it feels a lot like a workaround to me. |
This breaks the layout when using with a table (trying to animate components in flowbite-svelte, e.g.) |
It's 2024 and things are still not solved 😭😭😭
Error: |
Had the same, i made a (very ugly) solution. //Bind this to something to search a list of cards
let query: string = ''
{#each column.items as item (item.id)}
<div class="card hidden" animate:flip={{ duration: flipDurationMs }} class:show={query || item.name}>
{item.name}
{item.id}
</div>
{/each}
<style>
.show {
@apply block;
}
</style> I utilized a conditional to apply a class, allowing me to use CSS to toggle the visibility of the card. Since I'm using Tailwind CSS, you might need to define the classes to suit your requirements. Hope this solution is helpful for you. |
+1 same issue |
Yeah, this needs to get bumped up in the issues. Can't believe it's been 2 years since raised. Can't find a workaround at all with a table {#each} then Component when the Component has the tr. Tried to refactor to pull the tr out of the Component, but that has its own problems, see below:
|
Describe the problem
The animate directive is only allowed to an immediate child of a keyed each block.
As soon as the child might become more complex, the child element might be wrapped in its own component. That breaks the animate directive with the well known error message.
So from a developer experience perspective, this should be possible as well because inside that component the first element is technically still an immediate child of that each block.
I prepared two REPLs.
Describe the proposed solution
I can't fix this myself as the animate directive is resolved within the compiler I'm not so familiar with, yet.
And in Todo.svelte
And in Todo.svelte
Alternatives considered
Alternatives are quite tough.
As I will also use
in:receive
andout:send
crossfade transitions, I could try to identify the remaining items of the each loop by myself and put an animation on them.Importance
would make my life easier
The text was updated successfully, but these errors were encountered: