React Native
Return Key
Mobile Development
User Interface
Programming Tips

Identify Return Key action in React Native

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

In React Native, the keyboard return key can mean several different things: submit, move to the next field, dismiss the keyboard, or insert a newline. To identify the action correctly, you need to configure TextInput intentionally and listen to the right events instead of assuming the keyboard label alone controls behavior.

Use onSubmitEditing for Single-Line Submission

For ordinary single-line inputs, onSubmitEditing is the main event that signals the return key was used as a submit action.

tsx
1import React, { useState } from 'react';
2import { Text, TextInput, View } from 'react-native';
3
4export default function SearchField() {
5  const [query, setQuery] = useState('');
6  const [submitted, setSubmitted] = useState('');
7
8  return (
9    <View style={{ padding: 16 }}>
10      <TextInput
11        value={query}
12        onChangeText={setQuery}
13        placeholder="Search"
14        returnKeyType="search"
15        onSubmitEditing={() => setSubmitted(query.trim())}
16        style={{ borderWidth: 1, borderColor: '#888', padding: 10 }}
17      />
18      <Text style={{ marginTop: 12 }}>Submitted: {submitted}</Text>
19    </View>
20  );
21}

The important detail is that returnKeyType only changes the keyboard label. It does not automatically implement the action. The actual logic still belongs in onSubmitEditing.

Move Focus Through Form Fields

In a multi-field form, the return key usually means "next" until the final field, where it means "done" or "submit." That is easiest to implement with refs.

tsx
1import React, { useRef } from 'react';
2import { TextInput, View } from 'react-native';
3
4export default function SignupInputs() {
5  const emailRef = useRef<TextInput>(null);
6  const passwordRef = useRef<TextInput>(null);
7
8  return (
9    <View style={{ padding: 16, gap: 12 }}>
10      <TextInput
11        placeholder="Name"
12        returnKeyType="next"
13        onSubmitEditing={() => emailRef.current?.focus()}
14        style={{ borderWidth: 1, borderColor: '#888', padding: 10 }}
15      />
16      <TextInput
17        ref={emailRef}
18        placeholder="Email"
19        keyboardType="email-address"
20        returnKeyType="next"
21        onSubmitEditing={() => passwordRef.current?.focus()}
22        style={{ borderWidth: 1, borderColor: '#888', padding: 10 }}
23      />
24      <TextInput
25        ref={passwordRef}
26        placeholder="Password"
27        secureTextEntry
28        returnKeyType="done"
29        onSubmitEditing={() => {
30          // submit form here
31        }}
32        style={{ borderWidth: 1, borderColor: '#888', padding: 10 }}
33      />
34    </View>
35  );
36}

This pattern makes the user flow predictable and reduces the need for manual taps between fields.

Multiline Inputs Behave Differently

A multiline TextInput changes the meaning of return. Users usually expect a newline, not a submission event. That means comment boxes, notes, and message editors should often use an explicit button for submission rather than trying to overload the return key.

If you do want special behavior in a multiline field, test on both iOS and Android, because keyboard behavior and event timing can differ. This is one of those places where a code sample may work in one simulator and still feel wrong on a real device.

Use onKeyPress Only for Diagnostics or Special Cases

Sometimes you want to know whether the return key itself was physically pressed, not just whether the input submitted. In that case, onKeyPress can help, especially while debugging.

tsx
1<TextInput
2  onKeyPress={(e) => console.log('key:', e.nativeEvent.key)}
3  onSubmitEditing={(e) => console.log('submitted text:', e.nativeEvent.text)}
4/>

This can show whether the keyboard is sending Enter, whether onSubmitEditing is firing, or whether a wrapper component is swallowing props before they reach the real input.

Keep the Label and the Action Consistent

A field that shows a search return key should actually trigger search. A field that shows next should move focus. A field that shows done should complete input or dismiss the keyboard. If the label and action do not match, the interface feels broken even though the code is technically responding.

This consistency matters for accessibility too. Keyboard-driven flows are much easier to understand when the action label matches what happens next.

Common Pitfalls

  • Setting returnKeyType and assuming behavior changes automatically.
  • Using the same submit handler for every field in a form without field-specific logic.
  • Treating multiline inputs as if they were ordinary single-line submit fields.
  • Forgetting to forward onSubmitEditing or returnKeyType through custom wrapper components.
  • Testing keyboard flow on only one platform.

Summary

  • Use onSubmitEditing as the main signal for return-key submission in single-line inputs.
  • Treat returnKeyType as a label hint, not as the behavior itself.
  • Chain focus through form fields with refs for next behavior.
  • Expect multiline fields to prioritize newline insertion unless you design otherwise.
  • Validate return-key behavior on both iOS and Android before shipping.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.