headlessui: [Bug]: Transition applied on content instead of Disclosure panel
What package within Headless UI are you using?
What version of that package are you using?
v1.4.2
What browser are you using?
Chrome (Tested on Edge and Firefox)
Reproduction URL
https://codesandbox.io/s/headlessui-disclosure-transition-issue-6ogxj?file=/src/App.tsx
Describe your issue
When i use Transition component on Disclosure Panel, the transition is applied on content of panel instead of panel himself. I tried to use only documentation exemple, outside my project, but the exemple on documentation was already broken 🤔
(Note: I have volontarily increase the duration of transition to expect the beahavor)
(Note 2: I tried to use unmount
prop already, but seems to component was systematicaly unmounted regardless this prop)
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 7
- Comments: 16
Another workaround is to use the
Disclosure
component but manage its state manually usingstatic
, and then transition theheight
(ormax-height
to workaround the transition toauto
):@RobinMalfait What about the behaviour I described in my comment? the sandbox example you provided also shows it. When you expand the Disclosure, the panel appears instantly, or at least everything shifts down instantly and the contents emerge from 0 opacity gradually (based on transition time function and duration). This produces ugly jump of a page content below the disclosure which the Transition meant to avoid at the first place.
Hey! Thank you for your bug report! Much appreciated! 🙏
The transition is applied onto the
Disclosure.Panel
, I applied a background color to the panel that showcases this: https://codesandbox.io/s/headlessui-disclosure-transition-issue-forked-hzww3?file=/src/App.tsxThe issue with your example is that the purple background color is not coming from the
Disclosure.Panel
, but it is coming from theDisclosure
itself. This means that if you move the background color from theDisclosure
to theDisclosure.Panel
then your problem goes away: https://codesandbox.io/s/headlessui-disclosure-transition-issue-forked-kdtd9?file=/src/App.tsxYes, I found the solution! The solution is to DO NOT USE
headlessui/disclosure
component. I abandoned use of the component and just implemented my own super simplistic disclosure using thehttps://www.npmjs.com/package/react-animate-height
package.Here is my source code, it works for my needs, albeit is very simplistic:
Is there a correct way to do this with headlessui?
Is anyone else still getting this issue?
This issue should be reopen and fixed. All previous comments are valid: the component has a wrong and wired behavior when animating the Disclosure.Panel height.
Having the same behaviour. Pure example from the documentation doesn’t work as explained. Expectation is that the entire panel will transition but the result is very weird transition: the panel appears instantly and the content transitions within the duration time. Can somebody from headlessui team comment on this?
How are you marking this as completed man common don’t be lazy
In this example, if the height of the panel is greater than the screen, the panel will be truncated, I don’t think that’s a safe use case.
@hodbn this way you can’t use transitions other than max-height (opacity, scale etc),
transition-[max-height]
overwritestransition-property
set bytransition
. Can be fixed globally https://tailwindcss.com/docs/transition-property#customizing-your-themeActually I couldn’t just add height and max-height to default
transition
so ended up usingtransition-all
instead oftransition-[max-height]
Another option is using an arbitrary value like [transition-property: max-height opacity]Having the same problem myself on a custom drawer component