tailwindcss icon indicating copy to clipboard operation
tailwindcss copied to clipboard

The 'space-y-{number}' class adds spacing if the hidden element is the first child

Open mnme opened this issue 5 years ago • 3 comments

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

mnme avatar Dec 16 '20 13:12 mnme

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.

tkiryu avatar Dec 17 '20 01:12 tkiryu

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 👍🏻

adamwathan avatar Dec 17 '20 11:12 adamwathan

Okay, thanks for the feedback!

mnme avatar Dec 17 '20 12:12 mnme