I’ve been trying to animate the height of an element so that it reveals an error message underneath an input field, and was wondering if anyone could explain what’s going on here - it had me going round in circles for a while, and the wall began to look very appealing to my head…
The problem I was having was that the text was not being hidden in Chrome, although I later discovered that it was hidden correctly in Safari (OSX). I normally just use Chrome to test in initially, then when I’m happy with things I check it on other browsers, so I was only seeing the failure case for code that looked like it should be working.
I now have it fixed, but am wondering why the fix is needed, if it’s a bug, or just some quirk between browsers.
The fix is to explicitly set the height of the element being animated to 0px
.
There’s a simplified example Ellie here: https://ellie-app.com/8H8sYhW48c9a1
Line 76 in the Ellie is where the height is set to 0px
, if you remove this line you will see that in Chrome the text is not hidden, in Safari it is.
As you will also see in the Ellie, I am using Animator.Inline.style
to animate the height
which is initially set to 0px
until the animation is activated. Therefore, I figured this would be the initial height of the element containing the text, and the text would be clip
ped accordingly. When I took a look under the hood at the HTML, the inline style for the element was set to 0px
, and if I set the animation to run for a few seconds, I could see that the height
in the inline style was being updated correctly.
Looking further, I found that it appears to have something to do with flex-basis
, which, when I looked at the MDN docs…
I’ll stop right there because I’ve just re-read the docs on MDN while writing this, and see that flex-basis
is relevant to height
only in the case of flex-direction : column
. So I’ve just changed my container from Element.el
to Element.column
and the ‘fix’ described above is no longer required. Everything works as intended across all browsers (haven’t tested on IE).
I’d still be interested to know a bit more about this situation though if anyone can elaborate, (@mdgriffith (?))
Why does the ‘fix’ above work on an Element.el
? Should we be able to animate the height
of an Element.el
without the ‘fix’? Has this all come about due to a gap in my knowledge? (I can take a hit )
Thanks to anyone that can shed some light on this for me.