-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Allow Icon to receive ref #50816
base: master
Are you sure you want to change the base?
Allow Icon to receive ref #50816
Conversation
Ill test this out later today, but so far the code (for Icon) looks fine. this is probably going to be a nightmare to backport |
Why though? 🌞 |
|
||
const timeoutMs = 200; | ||
|
||
const StyledBroadcast = styled(Broadcast)` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is all a little bit too complex, let me know if you have a better idea on how to demonstrate usage of ref
. One thing I like about this example is that we're showing that we can just pass a ref through a styled generated component to the final Icon
, without having to change the ref
prop name along the way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I replaced it with a simpler example based on https://react.dev/reference/react/useRef#scrolling-an-image-into-view.
2577808
to
60a8073
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works fine for me
useEffect(() => { | ||
const interval = setInterval(() => { | ||
setIsShown(value => !value); | ||
}, timeoutMs * 3); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be configurable via prop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it was a real component then sure, but I don't think it matters that much for the story.
There's lots of files changed in this PR, but 205 of them are auto-generated.
I wanted to use an icon with
CSSTransition
, but I discovered that it's impossible without some kind of a wrapper sinceIcon
doesn't acceptref
. Using wrappers for icons is rather annoying, especially in the context of a flex parent, so I decided to refactorIcon
to acceptref
.First I had to update references of
JSX.Element
toReact.ReactNode
. This is because the new version ofIcon
returns the return value offorwardRef
, which is an object that React can render, but it's not a valid JSX element.https://www.totaltypescript.com/jsx-element-vs-react-reactnode
At the time of writing, this change doesn't require an update to teleport.e.
I ended up not needing to pass a ref to an icon, but I think it's worthwhile to keep this in case someone else runs into this.