Skip to content

Commit

Permalink
Allow changes to the className prop when the <Transition /> compo…
Browse files Browse the repository at this point in the history
…nent is currently not transitioning (#2722)

* allow changes to the `className` when we are _not_ transitioning

* update changelog
  • Loading branch information
RobinMalfait committed Aug 31, 2023
1 parent fa95262 commit d4aa86d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/@headlessui-react/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Ensure hidden `Tab.Panel` components are hidden from the accessibility tree ([#2708](https://github.com/tailwindlabs/headlessui/pull/2708))
- Add support for `role="alertdialog"` to `<Dialog>` component ([#2709](https://github.com/tailwindlabs/headlessui/pull/2709))
- Ensure blurring the `Combobox.Input` component closes the `Combobox` ([#2712](https://github.com/tailwindlabs/headlessui/pull/2712))
- Allow changes to the `className` prop when the `<Transition />` component is currently not transitioning ([#2722](https://github.com/tailwindlabs/headlessui/pull/2722))

### Added

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,15 +403,18 @@ function TransitionChildFn<TTag extends ElementType = typeof DEFAULT_TRANSITION_
unregister(container)
}, parentNesting)

let isTransitioning = useRef(false)
useTransition({
immediate,
container,
classes,
direction: transitionDirection,
onStart: useLatestValue((direction) => {
isTransitioning.current = true
nesting.onStart(container, direction, beforeEvent)
}),
onStop: useLatestValue((direction) => {
isTransitioning.current = false
nesting.onStop(container, direction, afterEvent)

if (direction === 'leave' && !hasChildren(nesting)) {
Expand All @@ -432,7 +435,11 @@ function TransitionChildFn<TTag extends ElementType = typeof DEFAULT_TRANSITION_
// Already apply the `enter` and `enterFrom` on the server if required
className: classNames(rest.className, ...classes.current.enter, ...classes.current.enterFrom),
}
} else {
}

// If we are re-rendering while we are transitioning, then we should ensure that the classes are
// not mutated by React itself because we are handling the transition ourself.
else if (isTransitioning.current) {
// When we re-render while we are in the middle of the transition, then we should take the
// incoming className and the current classes that are applied.
//
Expand Down

2 comments on commit d4aa86d

@vercel
Copy link

@vercel vercel bot commented on d4aa86d Aug 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

headlessui-vue – ./packages/playground-vue

headlessui-vue.vercel.app
headlessui-vue-tailwindlabs.vercel.app
headlessui-vue-git-main-tailwindlabs.vercel.app

@vercel
Copy link

@vercel vercel bot commented on d4aa86d Aug 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

headlessui-react – ./packages/playground-react

headlessui-react.vercel.app
headlessui-react-tailwindlabs.vercel.app
headlessui-react-git-main-tailwindlabs.vercel.app

Please sign in to comment.