-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
DOM Element Refs #41
Comments
I did find that you can wrap it in a Component class that works around this: const Input = styled('input')`font-size: 16px`
class InputWrapper extends React.Component {
render () { return <Input {...this.props} />; }
focus () { ReactDOM.findDOMNode(this).focus(); }
} |
Yes this is a needed feature. We need to extend the api for styled to accept an innerRef option. |
I tried my hand at it: #43 |
Closed in #43 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently it doesn't look like there is any way to get a reference to the DOM node. Setting a
ref
prop on the component always sets the ref to null (I think this is because it uses a functional component; React doesn't support refs on these). Styled-components allows ainnerRef
property for this. I looked at implementing this in emotion, but it looks like it might be a bit more complicated than I thought at first since you can wrap other styled components, not just DOM nodes.My use-case for this is to allow focusing a DOM node based on keyboard events. For this I need a reference to the actual DOM node to call
.focus()
, either usingfindDOMNode
or aref
on the actual DOM node. Any help or pointers are greatly appreciated.The text was updated successfully, but these errors were encountered: