Opacity of Dialog.Overaly after transition
See original GitHub issueWhat package within Headless UI are you using?
headlessui/react
What version of that package are you using?
1.0.0
What browser are you using?
Chromium Edge
Reproduction repository
https://github.com/cding91/IssueReproduce
Description
I grabbed the example code for Dialog. The example code uses transition on the opacity of the overlay. I intend to make use opacity-50 for the final looks of the overlay. I hope overlay’s opacity can transition from 0 to 50. What it did is shown in the code snippet below.
But it seems the overlay’s opacity changes from 0 to 50 then flashes to 100 (see the image). Is this the right behavior that I should expect? Is there something that I should or should not do to get the right transition? Thank you.
<Transition.Child
as={Fragment}
enter="transition duration-500"
enterFrom="opacity-0"
enterTo="opacity-50"
leave="transition duraiton-500"
leaveFrom="opacity-50"
leaveTo="opacity-0"
>
<Dialog.Overlay className="fixed inset-0 opacity-50 bg-gray-500" />
</Transition.Child>
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
How To Use Opacity and Transparency to Create a Modal in ...
You used opacity with pointer-events and transition to create a fade-in effect to display a modal on demand. You also used the various...
Read more >Fade in overlay in modal dialog - jquery - Stack Overflow
Is it possible to make the background opacity fade from 0% to 50%? If so, how? Because currently it feels kind of like...
Read more >Hide dialog overlay before the dialog is animated out of view ...
We have validated your query “How to hide the dialog overlay before the dialog animation out of view instead of after animation”.
Read more >HeadlessUI Dialogue Part 3 -Transitions - The Javascript
Just leave the as and show props at the Transition. Use the <Transition.Child> to wrap the overlay and content of the dialogue separately....
Read more >How to Use the Dialog Component with Headless UI and ...
<Dialog.Overlay className="fixed inset-0 bg-black opacity-30" /> Then, we can add style to the dialog contents. To style ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hey! The issue here is the
opacity-50
class that is sitting on the overlay element permanently:The way the transition component works, it adds the
enter
classes to the element at the beginning of the transition, meaning the element has these classes at first:Notice how both
opacity-50
andopacity-0
are on the element at the same time. This is a conflict, and whichever one appears later in the CSS file happens to win, in this caseopacity-50
soopacity-0
is never applied.The solution in general it to avoid conflicting classes being on an element at the same time. Using
bg-opacity-50
for the overlay is a great way to do that, another approach is to just use two separate elements, where the inner element is the actual 50% transparent overlay, and the outer element transitions from 0 to 100 opacity:Headless UI has no way to know it should remove the
opacity-50
class when it starts the transition and adds theopacity-0
class because it has no idea what those class names mean or anything.I was having the same/similar issue. Something like this worked for me:
Specify the desired opacity with a bg-opacity utility on the overlay itself. Animates nicely and has the desired effect.