-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Fix React forwardRef warnings for TooltipAnchor
s
#54492
Conversation
Size Change: -146 B (0%) Total Size: 1.62 MB
ℹ️ View Unchanged
|
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.
Thank you for working on this so quickly!
These changes look ok to me, I don't think they could any negative impact.
Could you add a CHANGELOG entry too, please?
packages/icons/src/icon/index.js
Outdated
* @param {IconProps} props icon is the SVG component to render | ||
* size is a number specifiying the icon size in pixels | ||
* Other props will be passed to wrapped SVG component | ||
* @param {import('react').Ref<SVGSVGElement>} ref The forwarded ref to the SVG element. |
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.
Since Icon
could be any JSX element, it's probably safer to go with any
(we do this in almost every components in the package)
Also, we usually use the ForwardedRef
type
* @param {IconProps} props icon is the SVG component to render | |
* size is a number specifiying the icon size in pixels | |
* Other props will be passed to wrapped SVG component | |
* @param {import('react').Ref<SVGSVGElement>} ref The forwarded ref to the SVG element. | |
* @param {IconProps} props icon is the SVG component to render | |
* size is a number specifiying the icon size in pixels | |
* Other props will be passed to wrapped SVG component | |
* @param {import('react').ForwardedRef<any>} ref The forwarded ref to the SVG element. |
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 use the SVGSVGElement
type because the description of the icon
prop says that it should render an SVG
component. Do you think if it matters here? I've changed that to HTMLElement
for now as I think it's probably better than any
? 😆
packages/primitives/src/svg/index.js
Outdated
* @param {SVGProps} props isPressed indicates whether the SVG should appear as pressed. | ||
* Other props will be passed through to svg component. | ||
* @param {import('react').Ref<SVGSVGElement>} ref The forwarded ref to the SVG element. |
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.
Same re. ForwardedRef
* @param {SVGProps} props isPressed indicates whether the SVG should appear as pressed. | |
* Other props will be passed through to svg component. | |
* @param {import('react').Ref<SVGSVGElement>} ref The forwarded ref to the SVG element. | |
* @param {SVGProps} props isPressed indicates whether the SVG should appear as pressed. | |
* Other props will be passed through to svg component. | |
* @param {import('react').ForwardedRef<SVGSVGElement>} ref The forwarded ref to the SVG element. |
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.
Thanks for the quick fix on this @kevin940726 🚀
It tests well for me.
After a changelog is added and the rest of @ciampo's suggested tweaks are made, this is good to go in my books.
What?
A bug introduced in #54450. This PR fixes the warning as originally reported in #53835 (comment).
Why?
Even though it's only a warning, it prevents the ref from being passed to the underlying DOM element, which might cause some unexpected behaviors.
How?
<TooltipAnchor>
implicitly requires the rendered child to be wrapped byforwardRef
so that it can pass its own refs down to the element. This is briefly mentioned [here] in the docs.This PR adds
forwardRef
to both the<Icon>
and the<SVG>
component.Testing Instructions
http://localhost:8888/wp-admin/site-editor.php?path=%2Fpatterns&categoryType=pattern&categoryId=all-patterns
forwardRef
when there are tooltips on the page.Testing Instructions for Keyboard
Same as above, it's a technical change that doesn't affect the UI.
Screenshots or screencast
N/A