Fix React forwardRef warnings for TooltipAnchors#54492
Conversation
|
Size Change: -146 B (0%) Total Size: 1.62 MB
ℹ️ View Unchanged
|
ciampo
left a comment
There was a problem hiding this comment.
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?
| * @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.
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.
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? 😆
| * @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.
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. |
aaronrobertshaw
left a comment
There was a problem hiding this comment.
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 byforwardRefso that it can pass its own refs down to the element. This is briefly mentioned [here] in the docs.This PR adds
forwardRefto both the<Icon>and the<SVG>component.Testing Instructions
http://localhost:8888/wp-admin/site-editor.php?path=%2Fpatterns&categoryType=pattern&categoryId=all-patternsforwardRefwhen 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