Replies: 2 comments 4 replies
-
💯 This is a common use-case. I brought in Headless UI thinking this would be possible, and I set something up like this: <Transition
show={showComponent1}
afterLeave={() => setShowComponent2(true)}
>
<p>This is component 1!</p>
<button type="button" onClick={() => setShowComponent1(false)}>
Show Component 2
</button>
</Transition>
<Transition
show={showComponent2}
afterLeave={() => setShowComponent1(true)}
>
<p>This is component 2!</p>
<button type="button" onClick={() => setShowComponent2(false)}>
Show Component 1
</button>
</Transition> However, this causes a layout shift, and there's no guarantee that the states of the two |
Beta Was this translation helpful? Give feedback.
-
I've built a SwitchTransition based on HeadlessUI some time ago which I'm using at work in production. You can check out the code and demo here: https://codesandbox.io/s/headless-ui-switch-transition-vkohn?file=/src/app.tsx Feel free to use it in your own projects! I'll propose to add it to HeadlessUI after the Tailwind CSS v3 release. Edit: Here comes the proposal SwitchTransition componentHeadless UI has a Transition component which works really well for showing and hiding things, but it isn't suited for transitioning from one element to another. For this, a different kind of transition is needed, usually it's called SwitchTransition (here is the SwitchTransition from React Transition Group). Moreover, I observed that none of the usual transition libraries handle switch transitions based on user input very well. With that I mean that the user might trigger another transition while a transition is currently ongoing. In the code example of React Transition Group the transition gets abruptly interrupted when I trigger another transition while the previous one is ongoing. I built a prototype of a SwitchTransition for Headless UI which serves two main goals:
This SwitchTransition component is already used in multiple projects in production for a couple months and works fine there. I'm happy to build a production version of this component and integrate it into Headless UI. The question here is whether the maintainers of Headless UI are interested in such a component as this will probably increase the maintenance surface for the project. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
It would be really neat if you could create a "sequenced transition" between two components where first the item exits and then the next one enters. Maybe this could be done by allowing a
transitionKey
prop (should be different fromkey
) where you can send any string and if it changes then it will first exit itself before entering itself again even thoughshown
stays unchanged?Or maybe the
show
prop not only allows for a boolean but also any string that has the same behaviour?Beta Was this translation helpful? Give feedback.
All reactions