https://github.com/sweenejp/sandbox/tree/fade-collapse-vanilla-js

The fade part of the animation is optional but I think generally looks nicer than without it.
One gotcha to be aware of if that the outer grid element needs to have overflow: hidden; which can result in some undesired behavior if some of the content of that element is supposed to have overflow. For example, an input’s focus-visible state might have an outline or something. If so, that outline could get cut off if the input inside the collapsing elements.
Most of the time, though, this is an easy way to animate collapsing content without reaching for a library.