Expand
<SlideDown>
componentAnimate height
Animating height is tricky because CSS can't transition to keyword auto
.
The .bf-expand
and .bf-expand-closed
classes utilise a css trick to animate
height
involving css grid
and two wrapping elements.
<div class="bf-expand">
<div>Expanded content</div>
</div>
<div class="bf-expand bf-expand-closed">
<div>Collapsed content</div>
</div>
<div class="bf-expand">
<div>Expanded content</div>
</div>
<div class="bf-expand bf-expand-closed">
<div>Collapsed content</div>
</div>
Together with a .bf-button-expand
button that toggles the
.bf-expand-closed
class you can make something like this:
Padding
Caveat; this technique does not work well with padding
on the immediate child
element.
Avoid padding on the child element of .bf-expand
<div class="bf-expand">
<div style="padding: 12px">Expanded content</div>
</div>
<div class="bf-expand">
<div style="padding: 12px">Expanded content</div>
</div>
Instead apply padding to a separate element
<div class="bf-expand">
<div>
<div style="padding: 12px">Expanded content</div>
</div>
</div>
<div class="bf-expand">
<div>
<div style="padding: 12px">Expanded content</div>
</div>
</div>
Sandbox
Overflow hidden
The .bf-expand
class applies overflow: hidden
in order to hide content while
transitioning between open/closed. This may have side-effects you don't want on
an expanded section (like a select dropdown or hover tooltip getting clipped).
This can be avoided by applying the .bf-expand-expanded
class when the content
has expanded (after transition
end
when opening).