The 'space-y-{number}' class adds spacing if the hidden element is the first child
Describe the problem:
Expected behaviour: adding the space-y-{number} class to a parent should not add space between visible and hidden child elements.
Actual behaviour: space-y-{number} adds space between hidden and visible elements if the hidden element is the first child of the parent.
Link to a minimal reproduction:
https://play.tailwindcss.com/g6tDf6CCYV
I think you can avoid this issue by adding hidden attribute to the hidden child as a workaround.
<form class="flex flex-col space-y-8 bg-red-200">
<input type="hidden" hidden>
<input type="text" class="border border-black" placeholder="Hello World">
<button type="submit" class="border border-black">Submit</button>
</form>
.space-y-{number} seems to be designed to only ignores children that have hidden attribute.
.space-y-{number} > :not([hidden]) ~ :not([hidden])
It might be a good idea to also ignore [type="hidden"] elements.
Yep it's not realistic to automatically ignore all invisible elements unfortunately because there are too many possible ways to make something invisible. If you have a hidden element inside a space group you need to add the hidden attribute for it to be ignored, or alternatively just don't put hidden elements in the group, keep them in a separate parent element. That's what I always do 👍🏻
Okay, thanks for the feedback!