danawoodman / react-fontawesome

A React Font Awesome component.
https://www.npmjs.com/package/react-fontawesome
MIT License
668 stars 72 forks source link

Add ref support #94

Closed streetlogics closed 3 years ago

streetlogics commented 3 years ago

I know this use case is specific to material-ui, but feels like the feature would be useful to have for other projects that use this.

Current use case:

import Tooltip from '@material-ui/core/Tooltip';
import FontAwesomeIcon from '@fortawesome/react-fontawesome';

....
return(
  <Tooltip><FontAwesomeIcon icon="coffee" /></Tooltip>
)

This currently throws an error because FontAwesomeIcon doesn't accept a ref attribute that points to the stored ref for the rendered element. I dug through the source here and seems pretty straightforward to add using https://reactjs.org/docs/refs-and-the-dom.html#creating-refs, but I haven't used Typescript a lot, so figured it would be best to just submit this as an official "issue"/request. Here's the material-ui docs referencing the issue as well in case it adds any additional clarity - https://material-ui.com/guides/composition/#caveat-with-refs

danawoodman commented 3 years ago

Howdy @streetlogics 👋, are you using FontAwesome 5 or 4? If you're using 5, have a look at the official component: https://github.com/FortAwesome/react-fontawesome

If you're on 4, I would accept a PR to support forwardRef in this repo but I'm not actively developing this anymore.

BTW, this repo doesn't use Typescript so you shouldn't need to worry about that unless I'm misunderstanding.

streetlogics commented 3 years ago

lol 🤦 I have no idea how I went from looking at the source here - https://github.com/FortAwesome/react-fontawesome/blob/master/src/components/FontAwesomeIcon.js to filing the issue in this project. Thanks for the response, I'll go post this there! 👍

EDIT: Turns out someone already reported it to - https://github.com/FortAwesome/react-fontawesome/issues/199 .

danawoodman commented 3 years ago

@streetlogics haha no worries, I've done as much or worse myself! Have a good day! 🍻