Skip to content
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

Get Field Component via refs #141

Closed
erickjth opened this issue Feb 5, 2018 · 7 comments · Fixed by #608
Closed

Get Field Component via refs #141

erickjth opened this issue Feb 5, 2018 · 7 comments · Fixed by #608

Comments

@erickjth
Copy link

erickjth commented Feb 5, 2018

Are you submitting a bug report or a feature request?

feature request

What is the current behavior?

There is no a way to get Field components via refs.

What is the expected behavior?

Access to the rendered component in a Field <Field {....} component={MyCustomField} />.

What's your environment?

  • final-form": "^4.2.0"
  • react-final-form": "^3.1.0

Other information

I am using this library in a React Native App, so the behavior that I would like to implement is this: Focus a field when clicking on "Next" key in the virtual keyboard on iOS.

@bogdansoare
Copy link

also having the same issue

@ibratoev
Copy link

ibratoev commented May 14, 2018

You can use a simple func to render your component like:

renderMyCustomField = props => <MyCustomField {...props} ref={customFieldRef] />
...
<Field {....} component={this.renderMyCustomField } />

@erickjth
Copy link
Author

erickjth commented Nov 21, 2018

Would be nice to have the official Forwarding Refs API implemented in each component to pass down the reference.

@TylerRick
Copy link
Contributor

TylerRick commented Aug 27, 2019

Yes, this is a must-have. I was very surprised when I tried adding a ref to a Field and it didn't work. (It gave me a ref to the Field component instead.)

Shouldn't be too hard to add this... Take a look at material-ui, for example. They wrap pretty much everything in a forwardRef, and also provide an inputRef if you want the ref for the input instead of the root/container element (such as FormControl). (I don't think there's any need for a separate inputRef for Field though.)

To do:

For what it's worth, here's the workaround I'm using (similar to @ibratoev's but using inline component so you don't have to come up externally create and name a wrapper component for each input component you're using):

Change:

                component="input"

to:

                component={props => <input {...props} ref={inputEl} />}

(Working demo here: https://codesandbox.io/s/react-final-form-how-to-get-ref-ekc6m)

@kopax
Copy link

kopax commented Apr 8, 2020

I am using react-native and react-final-form and this is kind of deal breaker not to have the forward ref, because I can't solve the UX requirement as follow: https://stackoverflow.com/questions/32748718/react-native-how-to-select-the-next-textinput-after-pressing-the-next-keyboar

Any update on this ?

@kopax
Copy link

kopax commented Apr 19, 2020

Hi and thanks @erikras for taking care of it, this could remain open till we can test it on our end don't you think?

@erikras
Copy link
Member

erikras commented May 27, 2020

Published fix in v6.5.0.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants