-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(react-motion): add MotionRefForwarder helper #35774
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
Merged
layershifter
merged 4 commits into
microsoft:master
from
robertpenner:feat/motion-ref-forwarder
Feb 24, 2026
+92
−25
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
33672d0
feat(react-motion): export MotionRefForwarder and useMotionForwardedRef
robertpenner 1d09cf9
refactor(react-dialog): use shared MotionRefForwarder from react-motion
robertpenner 3af92a0
refactor(react-message-bar): use shared MotionRefForwarder from react…
robertpenner 6952614
chore: fix names of change files
robertpenner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-dialog-6d4426ba-13e2-47e4-8358-70655d8b03cd.json
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "patch", | ||
| "comment": "refactor: use shared MotionRefForwarder from react-motion", | ||
| "packageName": "@fluentui/react-dialog", | ||
| "email": "robertpenner@microsoft.com", | ||
| "dependentChangeType": "patch" | ||
| } | ||
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-message-bar-1742f879-c20e-45d8-b47d-d8556c331970.json
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "patch", | ||
| "comment": "refactor: use shared MotionRefForwarder from react-motion", | ||
| "packageName": "@fluentui/react-message-bar", | ||
| "email": "robertpenner@microsoft.com", | ||
| "dependentChangeType": "patch" | ||
| } |
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-motion-dd97ba4e-2085-4615-a65c-4d4e7c5d8eec.json
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "minor", | ||
| "comment": "feat: export MotionRefForwarder and useMotionForwardedRef for shared motion ref forwarding", | ||
| "packageName": "@fluentui/react-motion", | ||
| "email": "robertpenner@microsoft.com", | ||
| "dependentChangeType": "patch" | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
21 changes: 0 additions & 21 deletions
21
packages/react-components/react-message-bar/library/src/components/MotionRefForwarder.tsx
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
51 changes: 51 additions & 0 deletions
51
packages/react-components/react-motion/library/src/components/MotionRefForwarder.test.tsx
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { render } from '@testing-library/react'; | ||
| import * as React from 'react'; | ||
|
|
||
| import { MotionRefForwarder, useMotionForwardedRef } from './MotionRefForwarder'; | ||
|
|
||
| const TestConsumer: React.FC = () => { | ||
| const ref = useMotionForwardedRef(); | ||
|
|
||
| return <div data-testid="consumer" ref={ref as React.Ref<HTMLDivElement>} />; | ||
| }; | ||
|
|
||
| describe('MotionRefForwarder', () => { | ||
| it('should provide a ref to children via context', () => { | ||
| const ref = React.createRef<HTMLElement>(); | ||
|
|
||
| const { getByTestId } = render( | ||
| <MotionRefForwarder ref={ref}> | ||
| <TestConsumer /> | ||
| </MotionRefForwarder>, | ||
| ); | ||
|
|
||
| expect(getByTestId('consumer')).toBe(ref.current); | ||
| }); | ||
|
|
||
| it('should provide undefined when not wrapped in MotionRefForwarder', () => { | ||
| let capturedRef: React.Ref<HTMLElement> | undefined; | ||
|
|
||
| const RefCapture: React.FC = () => { | ||
| capturedRef = useMotionForwardedRef(); | ||
| return null; | ||
| }; | ||
|
|
||
| render(<RefCapture />); | ||
|
|
||
| expect(capturedRef).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('should forward callback refs', () => { | ||
| const callbackRef = jest.fn(); | ||
|
|
||
| const { getByTestId } = render( | ||
| <MotionRefForwarder ref={callbackRef}> | ||
| <TestConsumer /> | ||
| </MotionRefForwarder>, | ||
| ); | ||
|
|
||
| const element = getByTestId('consumer'); | ||
| // The callback ref is passed via context to TestConsumer, which applies it to its div. | ||
| expect(callbackRef).toHaveBeenCalledWith(element); | ||
| }); | ||
| }); |
This file contains hidden or 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
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.