-
Notifications
You must be signed in to change notification settings - Fork 646
fix(Stack): correctly forward a Ref #6111
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
Conversation
🦋 Changeset detectedLatest commit: 9b47199 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
👋 Hi, this pull request contains changes to the source code that github/github depends on. If you are GitHub staff, we recommend testing these changes with github/github using the integration workflow. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR ensures that both Stack and StackItem components correctly forward refs to their underlying DOM elements by wrapping them in forwardRef.
- Imported and applied
forwardReftoStack - Imported and applied
forwardReftoStackItem - Adjusted prop types to include ref props
Comments suppressed due to low confidence (1)
packages/react/src/Stack/Stack.tsx:130
- [nitpick] The parameter name
forwardRefshadows the importedforwardReffunction and is inconsistent with theStackcomponent’sforwardedRef. Consider renaming this parameter toforwardedRef.
forwardRef: React.Ref<HTMLDivElement> | undefined,
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
size-limit report 📦
|
packages/react/src/Stack/Stack.tsx
Outdated
| className, | ||
| ...rest | ||
| }: StackProps<As> & React.ComponentPropsWithRef<ElementType extends As ? As : 'div'>, | ||
| forwardedRef: React.Ref<HTMLDivElement> | undefined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the type for this will get tricky because the forwardRef type should match whatever As is and I believe with the setup now it would always be HTMLDivElement.
The way this is typed also seems to be making the props inferred as any so they won't show up in autocomplete / won't fail if passed the wrong value (let me know if you're not seeing this locally though, could be something on my end)
<Stack
as="span"
ref={node => {
// `node` is `HTMLDivElement` instead of `HTMLSpanElement`
}}
// I don't think this will fail TS now the way the types are inferred
gap="nonsense"
/>There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I didn't notice 😅. I think I fixed it now, lmk what you think!
Co-authored-by: Josh Black <joshblack@github.com>
|
👋 Hi, there are new commits since the last successful integration test. We recommend running the integration workflow once more, unless you are sure the new changes do not affect github/github. Thanks! |
|
🟢 golden-jobs completed with status |
packages/react/src/Stack/Stack.tsx
Outdated
| ) | ||
| } | ||
| const StackItem = forwardRef( | ||
| <As extends ElementType>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think since we're casting StackItem below with as that the generic here and the StackItemProps/ref can also be removed 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yeah my bad, fixed!
|
👋 Hi, there are new commits since the last successful integration test. We recommend running the integration workflow once more, unless you are sure the new changes do not affect github/github. Thanks! |
|
👋 Hi, there are new commits since the last successful integration test. We recommend running the integration workflow once more, unless you are sure the new changes do not affect github/github. Thanks! |
…fix/stack-forward-ref
|
👋 Hi, there are new commits since the last successful integration test. We recommend running the integration workflow once more, unless you are sure the new changes do not affect github/github. Thanks! |
Closes #5446
Changelog
New
StackandStackItemin forwardRef callRollout strategy
Testing & Reviewing
Merge checklist