-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new data-attribute-based transition API #3273
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This has been around since 2020, but JSDOM doesn't know about this yet, so tests using JSDOM will fail otherwise.
thecrypticace
approved these changes
Jun 7, 2024
RobinMalfait
added a commit
that referenced
this pull request
Jun 19, 2024
Due to a timing issue bug, we updated the snapshot tests in #3273 incorrectly so this commit fixes that which is why there are a lot of changes. Most tests have `show={true}` but not `appear` which means that they should _not_ transition which means that no data attributes should be present.
RobinMalfait
added a commit
that referenced
this pull request
Jun 19, 2024
Due to a timing issue bug, we updated the snapshot tests in #3273 incorrectly so this commit fixes that which is why there are a lot of changes. Most tests have `show={true}` but not `appear` which means that they should _not_ transition which means that no data attributes should be present.
RobinMalfait
added a commit
that referenced
this pull request
Jun 19, 2024
Due to a timing issue bug, we updated the snapshot tests in #3273 incorrectly so this commit fixes that which is why there are a lot of changes. Most tests have `show={true}` but not `appear` which means that they should _not_ transition which means that no data attributes should be present.
RobinMalfait
added a commit
that referenced
this pull request
Jun 19, 2024
…ttributes (#3303) * add optional `start` and `end` events to `useTransitionData` This will be used when we implement the `<Transition />` component purely using the `useTransitionData` information. But because there is a hierarchy between `<Transition />` and `<TransitionChild />` we need to know when transitions start and end. * implement `<Transition />` and `<TransitionChild />` on top of `useTransitionData()` * update tests Due to a timing issue bug, we updated the snapshot tests in #3273 incorrectly so this commit fixes that which is why there are a lot of changes. Most tests have `show={true}` but not `appear` which means that they should _not_ transition which means that no data attributes should be present. * wait a microTask to ensure that `prepare()` has the time to render Now that we set state instead of mutating the DOM directly we need to wait a tiny bit and then we can trigger the transition to ensure a smooth transition. * cleanup `prepareTransition` now that it returns a cleanup function * move `waitForTransition` and `prepareTransition` into `useTransitionData` * remove existing `useTransition` hook and related utilities * rename `useTransitionData` to `useTransition` * update changelog * Update packages/@headlessui-react/src/components/transition/transition.tsx Co-authored-by: Jordan Pittman <jordan@cryptica.me> * add missing `TransitionState.Enter` This makes sure that the `Enter` state is applied initially when it has to. This also means that we can simplify the `prepareTransition` code again because we don't need to wait for the next microTask which made sure `TransitionState.Enter` was available. * add transition playground page with both APIs * update tests to reflect latest bug fix --------- Co-authored-by: Jordan Pittman <jordan@cryptica.me>
reinink
changed the title
Introduce CSS based transitions
Add new data attribute based transition API
Jun 21, 2024
reinink
changed the title
Add new data attribute based transition API
Add new data-attribute-based transition API
Jun 21, 2024
This was referenced Jul 13, 2024
This was referenced Jul 27, 2024
This was referenced Aug 15, 2024
This was referenced Aug 29, 2024
This was referenced Sep 6, 2024
This was referenced Sep 13, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We renamed the properties, see: #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.