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)

Most upvoted comments

The problem with this example specifically is that changing the height of a tr element doesn’t do anything. You can set it to 0 and it’ll still look the same. What does work is animating the line-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% accurate

  • Animating the line height looks weird because the text stays the same size until it’s gone:

line-height animation demo

  • If we animate the font size too, it solves the above problem, but it also looks weird because the text shrinks towards the top left rather than in the same direction as the transition:

font-size animation demo

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-row and/or table-cell: REPL

  • Add slide transition to both <tr>/<td> and child <div>
    • The <tr> and <td> dimensions cannot be animated, but the child <div> dimensions can be.
    • Also animating the parent <tr>/<td> fixes some jankiness that results from only animating the child element.
  • The table elements want to shift layout as dimensions are animated. Prevent this.
  • If both <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

Image

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, span and img elements are set to display: inline by default.

You can see the same behavior described above with the tr element happening with other inline-ish elements in this REPL. If (on line 43) you change the span element’s display property to block inline-block or even flex, 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.”