Skip to content
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

[Components] Tooltip throws error when child is a component #43129

Closed
danieliser opened this issue Aug 10, 2022 · 3 comments · Fixed by #48440
Closed

[Components] Tooltip throws error when child is a component #43129

danieliser opened this issue Aug 10, 2022 · 3 comments · Fixed by #48440
Labels
[Package] Components /packages/components [Type] Bug An existing feature does not function as intended

Comments

@danieliser
Copy link
Contributor

danieliser commented Aug 10, 2022

Description

When using the <Tooltip> component with an <Icon> as its only child is rendered it throws an error for passing ref to the component child.

Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?

Wrapping the <Icon> with a simple <span> resolves the error.

Even with the error it still renders properly and continue working from what I can tell.

Step-by-step reproduction instructions

<Tooltip text="Some Text">
	<Icon
		className="control-icon"
		onClick={ () => {} }
		icon='hidden'
	/>
</Tooltip>

Add <span> to resolve it.

<Tooltip text="Some Text">
	<span>
		<Icon
			className="control-icon"
			onClick={ () => {} }
			icon='hidden'
		/>
	</span>
</Tooltip>

Screenshots, screen recording, code snippet

image

Environment info

  • @wordress/env latest, after wp-env start --update, with gutenberg latest (not trunk) installed.

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@skorasaurus skorasaurus added [Package] Components /packages/components Needs Technical Feedback Needs testing from a developer perspective. [Type] Bug An existing feature does not function as intended labels Aug 11, 2022
@fabiankaegy
Copy link
Member

I'm also running into this same issue

@talldan talldan removed the Needs Technical Feedback Needs testing from a developer perspective. label Apr 13, 2023
@talldan
Copy link
Contributor

talldan commented Apr 13, 2023

I guess this happens because Tooltip wants a ref for the Icon element, but Icon doesn't support forwarding refs.

Tooltip uses cloneElement to inject a ref, so it's not very apparent to the implementer that supporting refs is a requirement.

That's my technical feedback.

@danieliser
Copy link
Contributor Author

I assume that's a neccesary requirement to prevent actually wrapping the element with extra html?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Components /packages/components [Type] Bug An existing feature does not function as intended
Projects
Status: Done 🎉
Development

Successfully merging a pull request may close this issue.

4 participants