svelte: Transitions don't work on table row addition
Describe the bug
When I add a row to a table, even when the table has transition: set, it just pops in ignoring the transition. Oddly, it works on removing the row.
Logs No logs.
To Reproduce Reproducible bug: https://svelte.dev/repl/f7fefbd5eb63471db69a89bf36398d38?version=3.23.0
Based on demo: https://svelte.dev/tutorial/local-transitions which uses divs
Expected behavior Transitions should work on both adding a removing a table row.
Information about your Svelte project:
-
Your browser and the version: Google Chrome Version 83.0.4103.61 (Official Build) (64-bit)
-
Svelte version 3.23
repl, none
Severity Not much, it’s just some coolness in transitions with adding. But it does help the user acclimate to the changes on the screen.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 6
- Comments: 15 (7 by maintainers)
The problem with this example specifically is that changing the height of a
trelement doesn’t do anything. You can set it to 0 and it’ll still look the same. What does work is animating theline-height, but this has some problems:The default value is
normal, and it’s pretty much up to the browser what this value is, so we have to guess. It’s apparently around 1.2em (MDN reference), so can estimate by just multiplying the font size by 1.2, but wouldn’t necessarily be 100% accurateAnimating the line height looks weird because the text stays the same size until it’s gone:
So yeah, unless someone else has a better solution, this seems pretty hacky and I would guess unwanted? Although, it could be justified if only being applied to this edge case with table elements. Let me know if worth sending in a PR
I figured out how to get the slide transition to work with
display: table-rowand/ortable-cell: REPL<tr>/<td>and child<div><tr>and<td>dimensions cannot be animated, but the child<div>dimensions can be.<tr>/<td>fixes some jankiness that results from only animating the child element.<tr>and<td>need to be animated, ensure the the correct slide axis is used. (Animating both axes at the same time also works, but looks a little odd.)My use-case was a table whose rows open up a details view when clicked (for viewing on mobile): https://veneer.vercel.app/v/s.1o5t26He2DzTweYeleXOGiDjlU4Jkx896f95VUHVgS8U
I’m also running into this.
This won’t be limited to Table Rows, pretty confident this will be the case on any element that doesn’t have a Block Level display property… For instance,
spanandimgelements are set todisplay: inlineby default.You can see the same behavior described above with the
trelement happening with other inline-ish elements in this REPL. If (on line 43) you change the span element’s display property toblockinline-blockor evenflex,grid, or any other block-ish layout, the transition works as expected.A possible developer warning (I imagine) would only need to be something along the lines of: “The slide transition animates the height of an element. That being said, it will only work properly with block-level elements: those that can accept a height within document flow.”