-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix React forwardRef warnings for
TooltipAnchor
s (#54492)
* Forward refs for SVG and Icon components * Address code review * Fix unit test * Add changelog
- Loading branch information
1 parent
cef6d46
commit 62c1f50
Showing
4 changed files
with
40 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,25 +1,27 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { cloneElement } from '@wordpress/element'; | ||
import { cloneElement, forwardRef } from '@wordpress/element'; | ||
|
||
/** @typedef {{icon: JSX.Element, size?: number} & import('@wordpress/primitives').SVGProps} IconProps */ | ||
|
||
/** | ||
* Return an SVG icon. | ||
* | ||
* @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 {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<HTMLElement>} ref The forwarded ref to the SVG element. | ||
* | ||
* @return {JSX.Element} Icon component | ||
*/ | ||
function Icon( { icon, size = 24, ...props } ) { | ||
function Icon( { icon, size = 24, ...props }, ref ) { | ||
return cloneElement( icon, { | ||
width: size, | ||
height: size, | ||
...props, | ||
ref, | ||
} ); | ||
} | ||
|
||
export default Icon; | ||
export default forwardRef( Icon ); |
This file contains 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 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