[Component] Custom Icons give console error and do not allow tooltips.
See original GitHub issueI am trying to load icons from React-Icons, and when i use <Icon as={MdPeople} />
for example I get the following error in console: (I tried it with <Box />
with the same result)
Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?
Check the render method of `Context.Consumer`.
in MdPeople (created by Context.Consumer)
in Styled(div) (created by Icon)
in Icon (at PartnerIcon.tsx:20)
in Tooltip (at PartnerIcon.tsx:14)
...
My componnet looks like so:
import React from 'react'
import { Team } from 'types/Team'
import { MdPeople } from 'react-icons/md'
import { Tooltip, Icon } from '@chakra-ui/core'
type Props = {
team: Team
}
export const PartnerIcon = ({ team }: Props) => {
// use user to determine if this should be rendered.
return (
<Tooltip
label={`Partner ${team.name}`}
aria-label="Partner"
placement="top"
hasArrow
>
<Icon color="white" as={MdPeople} /> // tried this with <Box as... /> with the same result.
</Tooltip>
)
}
On top of this error, It does not show a tooltip when I hover over the icon. - I want to point out that the tooltip works fine when used with a normal icon.
Not exactly sure how to debug this.
Oh also, if you wrap a <Tooltip>
element around this example you can see that the tooltip does not render: https://chakra-ui.com/icon#adding-custom-icons
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Material UI tooltip doesn't display on custom component ...
The following can hold a ref: Any Material-UI component; class components i.e. React.Component or React.PureComponent; DOM (or host) components ...
Read more >4 Ways to Show Tooltips in React with react-tooltip, Material UI ...
This is done with the data-tip and data-for custom attributes. We specify these attributes for the <button> element, but you can display ......
Read more >How To Make an Extremely Reusable Tooltip Component ...
All you need to do is import the Tooltip component and use it as a wrapper. Make it go above anything you want...
Read more >Components - Bootstrap
Icon classes should only be used on elements that contain no text content and have no child ... Tooltips & popovers in button...
Read more >Create a custom tooltip component in Vue - LogRocket Blog
vue create tooltips. Let's delete the default components in our new project and make sure that nothing renders in the browser.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m facing the same issue. While
react-icons
doesn’t supportforwardRef
, a quick solution would be to add the icon as a child:This issue is happening because
react-icons
doesn’t useforwardRef
and tooltip can’t work correctly withoutref
placed in the icon.See here: https://github.com/react-icons/react-icons/blob/f95cf84f7beff3638be8bb12a51d00338da97100/packages/react-icons/src/iconBase.tsx#L30
@with-heart I’ll suggest we open an issue or PR in
react-icons
repo to get this fixed.I believe it works well if you use any icon from
@chakra-ui/icons
Thanks guys.