-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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
[TextInput] iOS Keyboard next/prev Buttons & tab Support #641
Comments
Update 😑 should have updated before submitting, but updating Before update: <TextInput
// ...
returnKeyType='go'
/> |
How to focus on the second TextInput? |
bump |
I would love to take a stab at it, but I'm not convinced I'm quite up to the task of a PR into react-native core 😅 I'll be very interested to check out your work if you get a PR submitted @brentvatne 😄 |
For single-line text fields, the onSubmitEditing handler (or similar) should suffice. What is missing from it to let you solve this use case? |
The back/forward form navigation buttons are a iOS browser feature, not a native iOS app feature. These buttons will show up automatically if you display an HTML form inside a WebView, but there is no API for displaying these buttons in native iOS apps, and any app that you have seen using them is either using a WebView, or has re-created the same feature natively using custom code (presumably for the purpose of making their native form behave more like a web form - a somewhat dubious UX decision IMHO). It would certainly be possible to implement a facsimile of this feature right now as a native module, and if the demand is high enough then I expect someone will build it (maybe even us), but for the record, if I was developing a native iOS app and the designer asked for this, I would push back and suggest that they try to implement forms using native iOS app design patterns rather than iOS mobile web patterns. You'll notice that the iOS Settings app never once uses this pattern, despite having pages and pages of form fields. That said, we are currently investigating the best way to implement inputAccessory views (the docked bar that appears above the keyboard that can be used for adding additional application-specific controls), and once that is in place, it should be relatively simple to implement this feature in JS code. |
Can the "return" key move to next text input field? Looking around the documentation, it seems like we can display the "return" key as a "next", but it won't actually move to the next input field -- it'll just dismiss the keyboard. As @nicklockwood says, back/forward form navigation buttons aren't a native iOS app feature. Moving to the next field is, though. It'd probably be more important to implement that. Edit: remove incomplete sentence. |
@dvdhsu unlike web forms, iOS has no natural concept of tabbing order, or the "next field", so we cannot easily replicate that automatically. If you register an event handler for onSubmitEditing, it should fire when the return key is pressed, and you can then call focus() on the next field in the form. |
@dvdhsu I've not actually tried building a form like this in practice, so if you find that it doesn't work, or if you have some ideas for how to make it simpler to implement, I'd be keen to hear them. |
@nicklockwood - thank you the detailed response, your expertise is much appreciated. @ide - you're right, that will work just fine for the most part. If you have a username and password field, you can just focus the password in the |
@dvdhsu - there are a good number of cases where you might want the Next button to do something other than go to the next text field. For example you might want to transition to the next screen, or focus the next text field that doesn't yet have valid input (ex: if the user filled them out out-of-order). For the use case you mentioned: if I understand it correctly, to move to the next field you could get refs to all of the text fields and then call this.refs[desiredTextField].focus(). This is pretty lightweight and opens the opportunity for custom logic like skipping over certain fields, etc. |
@ide - yep, that's the use case I was referring to. Your solution is fine, but like @brentvatne notes, it'd be better to have some sort of function s.t. we didn't need to hardcode the transitions in for longer forms. Also -- If I have time over the next week, I'll have a think about this, and implement something. Thanks! |
@dvdhsu Having the keyboard dismissed automatically onSubmitEditing is probably a bug - it doesn't match the native iOS behaviour. I think it would make sense if we kept this as default behavior if onSubmitEditing isn't set (to avoid breaking existing code), but if onSubmitEditing is set then we disable it and leave it up to the JS to dismiss the keyboard. |
Now that I think about it, we could probably implement select-next field automatically as well by making the following changes:
@vjeux would you be in favour of something like this? And if so, @ide, @dvdhsu, do you feel like creating a pull request to implement some or all of the above? (I'll be happy to finish the job if you can at least make a start with it) |
@nicklockwood - that sounds fantastic to me |
@nicklockwood that works with me. |
@nicklockwood late to the party here - but that sounds like a happy balance. Any ETA on this? |
@admmasters - @auser mentioned in irc that he was interested in doing this. @auser - is that still the case? If you're too busy I can have a look at it soon |
@brentvatne Yes, I hope to get to it this weekend. I've had a bit of personal junk going on lately. I'll check in with you on irc. |
+1 any update on this? |
I don't think that it's a good idea to implement this in an "automatic" way. I think that we just have two problems here:
|
I've implemented a Basically, it allows for backward compatibility by defaulting to In the case of switching to different fields...the user would set It's not an automated way to manage all of this as way mentioned above, but it's a simple solution that works. |
+1 would love to see progress on the original issue raised here--I would love to see a built-in "next" feature for TextInput, as well as support for tabs for hardware keyboards |
+1, any news or workaround ways, guys? how did you solve it in your projects? |
This works reasonably well as a workaround: http://stackoverflow.com/questions/32748718/react-native-how-to-select-the-next-textinput-after-pressing-the-next-keyboar With this system, if using an attached keyboard, hitting enter works, but hitting tab doesn't |
I think this is a very important issue because it's a common requirement -- pretty much every app has forms and it sucks that everyone needs to come up with a one-off solution for how to handle this. We need You will want to look at, in detail, how this is handled on iOS, Android, and web, understand the strengths and weaknesses of each, and try to build the best implementation around that, which ideally would have a web-like API. I created a ProductPains issue for this here: https://productpains.com/post/react-native/keyboard-nextprev-buttons-tab-support/ |
I am using react native with clojurescript and reagent. I would not like to have an automatic behaviour for this. What I am missing is a simple "focus" property. If a value is set for this property this text input field should have focus as long as this property is true and should not have focus when the property is false. In this way I can easily just save in my state object which field has the focus. |
@Knotschi see http://stackoverflow.com/a/35070812/2397068 for one implementation of this |
yeah, I saw this and just added an answer for reagent. I still think there should be a focus prop in react native |
@Knotschi - what would you expect the framework to do if two or more TextInputs have focus set to |
@brentvatne would it be possible for the (The most recently mounted TextInput w/ |
Hi there! This issue is being closed because it has been inactive for a while. But don't worry, it will live on with ProductPains! Check out its new home: https://productpains.com/post/react-native/textinput-ios-keyboard-nextprev-buttons-tab-support ProductPains helps the community prioritize the most important issues thanks to its voting feature. Also, if this issue is a bug, please consider sending a pull request with a fix. |
This worked fine for me. Tab from UN to Password, then to login by just swallowing the tabs. Not the finest solution but it will work for someone :) handleChangeEmail = (text) => {
// capture tabs
if (text.match(/.+\t/)) {
this.refs.password.focus()
} else {
this.setState({ email: text })
}
}
handleChangePassword = (text) => {
// capture tabs
if (text.match(/.+\t/)) {
this.handleLogin()
} else {
this.setState({ password: text })
}
} |
@lrettig that solution was perfect - thanks! |
So I'm trying to shift focus from my username field to my password field and refs are deprecated while everything else doesn't seem to work in the most recent version of RN, any updates on this? |
@danstepanov same here... :( |
I don't see any way to capture physical keyboard tab keys. They don't trigger a onChangeText so I can't sniff for them. On 39.02. |
Any update on this? |
Bump. |
If anyone has an interest, take a look at https://github.com/douglasjunior/react-native-keyboard-manager |
@danstepanov if you want to move on enter to the next fields, check this out: https://github.com/zackify/react-native-autofocus |
@douglasjunior's answer helped me. Thank you, Douglas |
How is this discussion dead? Seems like a necessary tool to have a sort of |
I have been unable to find throughout the documentation, UIExplorer, or my own experiments a way to enable iOS keyboard navigation and submit elements. I feel like this is important and expected from users to be able to navigate between input elements and submit from the iOS keyboard.
This behavior is present/expected even on vanilla HTML forms accessed via iOS on the web.
If somebody already has a solution for this, please let me know 😄
Request
TextInput
and other user input elementsScreen shot showing "next"/"prev" elements
The text was updated successfully, but these errors were encountered: