-
Notifications
You must be signed in to change notification settings - Fork 1
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
Cannot programmatically focus the textarea input in the Textarea component #470
Comments
I ran into this issue yesterday with our base Can we use Ideally this would be applied to all of our inputs, but I'm ok with that being a separate PR to expedite the fix for Artlook |
That being said, we will probably run into an issue with how I initially thought we might be able to get away with something like the below, but haven't tested it. I did see one SO post that said it wasn't working for them. <Field
name="content"
component={(props) => <Input ref={inputRef} {...props} />}
/> This approach may have some downsides when it comes to react dev tools and component display names. It's also not very dev friendly. Another workaround could be to also accept a export default React.forwardRef(function Input ({ forwardedRef, ...inputProps }, ref) {
return (
<input ref={forwardedRef || ref} {...inputProps} />
)
}) |
Yeah, that was originally was my hope (to just export our component with I plan on getting a PR up for this today! |
@chawes13 I'm running into some bumps in the road represented by this issue. Does that make sense in that I need to define prop types and default props after exporting |
@danparnella Did you try the solution outlined in this comment? facebook/react#16653 (comment) I think you would want to do something like const Input = React.forwardRef(function Input (props, ref) { return <input ref={ref} {...props} /> })
Input.propTypes = propTypes
Input.defaultProps = defaultProps
export default Input |
Got it, got it. Ok, just wanted to make sure I didn't go too off the rails with our patterns 👍 . |
Uncharted territory 🤪 |
Without using DOM traversal with standard Javascript, I haven't been able to find a way to programmatically focus the textarea input in the
Textarea
component. My suggestion is to allow for aforwardRef
prop onTextarea
that would be passed down to the textarea input. That ref could then be used to target the input itself for focusing.The text was updated successfully, but these errors were encountered: