Closed RobinMalfait closed 3 weeks ago
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
headlessui-react | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Jun 7, 2024 9:31am |
headlessui-vue | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Jun 7, 2024 9:31am |
We renamed the properties, see: https://github.com/tailwindlabs/headlessui/pull/3285
This PR adds a new way of dealing with transitions. Instead of using the
<Transition />
component and using theenter
,enterFrom
,enterTo
,leave
,leaveFrom
andleaveTo
props, we can now define all of that in CSS.Most components that are rendered conditionally based on the state of the component:
ComboboxOptions
DisclosurePanel
ListboxOptions
MenuItems
PopoverPanel
Will now accept a
transition
prop. The moment that is enabled then we will exposedata-from
,data-enter
,data-exit
anddata-transition
data attributes at the correct time. You can use these data attributes in your CSS or Tailwind Classes to style these components.The lifecycle of the data attributes look like this:
data-transition
attribute is added if anenter
orexit
transition is happening.data-enter
attribute is added during the fullenter
transition from start to finish.data-exit
attribute is added during the fullexit
transition from start to finish.The
data-from
attribute is applied at different times depending on theenter
orexit
transition. The styles applied usingdata-from
are for describing thefrom
state or theinitial
state.enter
transition we will add thedata-from
attribute briefly to make sure that state is present in the DOM. Then, we take it away and let the browser transition the DOM node to it's default state (e.g.: opacity-100).exit
transition we will add thedata-from
attribute (and keep it there) after the transition starts because then we can go from the current state to thedata-from
state until finished. Once finished, we will unmount the DOM node.For example, let's say you want to fade in the
MenuItems
, previously you would use the<Transition />
component for that:There are a few things you might notice:
enterFrom
andleaveTo
are the sameenterTo
andleaveFrom
are the sameenterTo
andleaveFrom
are the default state of an elemententer
andleave
are the sameTo use the data attribute approach, you can represent this like:
The
transition duration-200 ease-out
were the same, so we can always define them.The
data-from
data attribute represents the initial state, so we can define it once and it will be applied at the correct time.If the
duration
oreasing
function is different depending on whether we areentering
orexiting
, then we can do that explicitly as well:Before:
After:
If the
enter
andleave
states are different, e.g.: when entering from the left, and exiting to the right. Then we can combine the data attributes:After:
Notice that we didn't specify the
translate-x-0
case because that's again the default state of an element.The existing
<Transition>
and<TransitionChild>
will also expose these data attributes to the underlying DOM node so that you can use them in your CSS for components or elements that don't have atransition
prop.