Closed tjallingt closed 5 years ago
We forward props on these components so you should be able to just set ref
in the usual manner. If I’m missing something, please provide a code sample that shows what is currently not-working so we can understand your need better :)
Admittedly i didn't test them all. I just tried to focus the TextField and it didn't work see this example: https://codesandbox.io/s/m74o6yykv9
AFIAK forwarding props doesn't work with refs since React swallows those (just like it swallows the key
prop). refs on class components point to the class instance (which can or cannot be intended behaviour) but refs on function components just plain don't work without React.forwardRef
.
Note: using react hooks for brevity, shouldn't change the functionality (but i didn't test it so who knows really)
Ah, yes, you're right about key
and ref
getting swallowed, my mistake. We will switch to using forwardRef
-- thank you for the excellent report and information!
@tjallingt Version 2.1.0 has been published, could you please verify that refs work as you expect and let me know?
Great! Everything works as expected. Even <Spinner />
got a ref 😄
https://reactjs.org/docs/forwarding-refs.html
React.forwardRef can be applied to "simple" styled components to give developers access to the underlying dom node. Probably useful on
Button
,Checkbox
,DropdownSelect
,Pill
,Radio
andTextField
components.