Skip to content

Commit b0ccc78

Browse files
authored
Ensure the ref is forwarded on the Transition.Child component (#1473)
* use `forwardRef` on the `Transition.Child` component * update changelog
1 parent 517ca77 commit b0ccc78

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2828
- Ensure the `Popover.Panel` is clickable without closing the `Popover` ([#1443](https://github.com/tailwindlabs/headlessui/pull/1443))
2929
- Improve "Scroll lock" scrollbar width for `Dialog` component ([#1457](https://github.com/tailwindlabs/headlessui/pull/1457))
3030
- Make the `ref` optional in the `Popover` component ([#1465](https://github.com/tailwindlabs/headlessui/pull/1465))
31+
- Ensure the `ref` is forwarded on the `Transition.Child` component ([#1473](https://github.com/tailwindlabs/headlessui/pull/1473))
3132

3233
## [@headlessui/react@1.6.1] - 2022-05-03
3334

packages/@headlessui-react/src/components/transitions/transition.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -411,21 +411,21 @@ let TransitionRoot = forwardRefWithAs(function Transition<
411411
)
412412
})
413413

414-
function Child<TTag extends ElementType = typeof DEFAULT_TRANSITION_CHILD_TAG>(
415-
props: TransitionChildProps<TTag>
416-
) {
414+
let Child = forwardRefWithAs(function Child<
415+
TTag extends ElementType = typeof DEFAULT_TRANSITION_CHILD_TAG
416+
>(props: TransitionChildProps<TTag>, ref: MutableRefObject<HTMLElement>) {
417417
let hasTransitionContext = useContext(TransitionContext) !== null
418418
let hasOpenClosedContext = useOpenClosed() !== null
419419

420420
return (
421421
<>
422422
{!hasTransitionContext && hasOpenClosedContext ? (
423-
<TransitionRoot {...props} />
423+
<TransitionRoot ref={ref} {...props} />
424424
) : (
425-
<TransitionChild {...props} />
425+
<TransitionChild ref={ref} {...props} />
426426
)}
427427
</>
428428
)
429-
}
429+
})
430430

431431
export let Transition = Object.assign(TransitionRoot, { Child, Root: TransitionRoot })

0 commit comments

Comments
 (0)