Popover Causing Height to Increase #3647
Replies: 1 comment
-
Hey! All Headless UI components are headless and don't ship with any styles. The function UserButton() {
return (
<div className="relative">
<button>
<UserIcon className="size-10 hover:brightness-110" />
</button>
</div>
)
} Even more simplified in Tailwind Play example: https://play.tailwindcss.com/T712ix6vUU I don't think there is anything we can do in Headless UI since we don't ship any styles. I also never looked into why the browser behaves this way. I typically use a flexbox container anyway so I would suggest to do the same to solve it 👍 Not a satisfying solution / explanation I'm afraid. But I hope this helps! |
Beta Was this translation helpful? Give feedback.
-
I'm using a Popover component and its height increases beyond its internal components and offsets them upwards unless the display property is set to
flex
orcontents
or the height is manually set to the height of its contents or less. Here's the Popover component. All the code was copied over directly from the headlessui except I replaced the PopoverButton contents with an SVG component and added a transition to it (also copied from the headlessui website):And here's the UserIcon component that's being used for the PopoverButton:
And finally here's the parent component that contains the Popover component:
I'm fairly certain I tracked the issue down to the Popover component. When I inspect the element, it shows its dimensions as
40x46
. However when I set the Popover display toflex
the issues goes away (it correctly fits the contents) and the dimensions get set to40x40
and when I switch the display tocontents
that also fixes the issues and the dimensions change toauto x auto
. When inspecting the element it doesn't show any margin nor padding, but just in case I also tried explicitly setting padding and margin to 0 and the size and height to auto and fit, but none of that fixed the issue.When I add different background colors to the Popover and UserIcon (and PopoverButton), you can see that it's the Popover element itself with the incorrect height.
Here's a picture showing the initial Popover height issue with it's display property not manually set to anything and the Popover element with a red background and the contents of the PopoverButton with a green background:

Here's a picture showing the Popover height issue fixed with it's display property set to

flex
:And here's a picture showing the Popover height issue fixed with it's display property set to

contents
:I don't have a screen cap of the PopoverButton background colored but I confirmed that it's the same size as its contents (the UserIcon component). If this issue does happen to be caused by something I have configured on my end or this is expected and intended behavior of the component then my bad, but I don't believe either of those are the case and this could cause potential layout issues for users of the component as it did for me.
Beta Was this translation helpful? Give feedback.
All reactions