Course contentsShow
← React Native
Lesson 185 of 1,5553. Core Primitive ComponentsFree lesson

Handling Keyboard Return Behaviors

Learners will configure the keyboard action button to perform custom submission logic.

In this lesson, you will learn how to customize the "action button" on your soft keyboard so it triggers specific logic when a user finishes typing.

Why Customize the Return Key?

When a user types into a TextInput, the keyboard usually displays a generic "Return" or "Enter" key. However, depending on your app's flow, you might want that button to say "Search," "Send," "Done," or "Next." More importantly, you want that button to do something specific—like submitting a form or jumping to the next field—instead of just adding a new line of text.

Configuring the Return Behavior

React Native provides two primary props on the TextInput component to control this: returnKeyType and onSubmitEditing.

  1. returnKeyType: This determines the label displayed on the button (e.g., 'done', 'go', 'next', 'search', 'send').
  2. onSubmitEditing: This is a callback function that fires the moment the user taps that action button.

Here is a quick example of a search input that triggers a function when the user taps "Search":

<TextInput
  placeholder="Search for items..."
  returnKeyType="search"
  onSubmitEditing={() => console.log("Searching for your query...")}
/>

Bridging the Experience

By default, a multi-line TextInput treats the return key as a line break. If you are building a single-line form, setting the returnKeyType helps the user understand the context of the input.

If you have a form with multiple fields, you can use the onSubmitEditing prop in combination with ref chains (which you learned in lesson 23) to programmatically focus the next TextInput when the user taps "Next." This creates a fluid, professional experience where the user doesn't have to manually tap the next field. Using these properties ensures your app feels like a native part of the user's phone, rather than a generic web-like experience.

Key Takeaway: Use returnKeyType to set the keyboard's label and onSubmitEditing to execute your custom logic, making your forms feel intuitive and responsive.