From 943efab7a5d3562a244de510a0d6dde789050229 Mon Sep 17 00:00:00 2001 From: Boris Yankov Date: Fri, 13 Nov 2026 16:13:43 +0200 Subject: [PATCH] Keep input focus on Enter when enterKeyHint is "next" React Native blurs a single-line TextInput on submit by default, which hides the keyboard before an onKeyDown handler can move focus to the next field. On web, Enter never blurs an input. Set submitBehavior to "submit" for html.input when enterKeyHint is "next" and an onKeyDown handler is provided. --- .../createStrictDOMTextInputComponent.js | 5 ++++ .../src/types/renderer.native.js | 1 + .../tests/html/html-test.native.js | 29 +++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/packages/react-strict-dom/src/native/modules/createStrictDOMTextInputComponent.js b/packages/react-strict-dom/src/native/modules/createStrictDOMTextInputComponent.js index 0446fa36..2f0fa90d 100644 --- a/packages/react-strict-dom/src/native/modules/createStrictDOMTextInputComponent.js +++ b/packages/react-strict-dom/src/native/modules/createStrictDOMTextInputComponent.js @@ -137,6 +137,11 @@ function applyTextInputProps( } if (enterKeyHint != null) { nativeProps.enterKeyHint = enterKeyHint; + // On web, Enter does not blur an input. Keep focus on "next" so that an + // onKeyDown handler can move focus without the keyboard hiding in between. + if (tagName === 'input' && enterKeyHint === 'next' && onKeyDown != null) { + nativeProps.submitBehavior = 'submit'; + } } if (maxLength != null) { nativeProps.maxLength = maxLength; diff --git a/packages/react-strict-dom/src/types/renderer.native.js b/packages/react-strict-dom/src/types/renderer.native.js index 4f91a652..6908fbc0 100644 --- a/packages/react-strict-dom/src/types/renderer.native.js +++ b/packages/react-strict-dom/src/types/renderer.native.js @@ -123,6 +123,7 @@ type ReactNativeProps = { src?: ImageProps['src'], srcSet?: ImageProps['srcSet'], style: ReactNativeStyle, + submitBehavior?: TextInputProps['submitBehavior'], testID?: ViewProps['testID'], value?: TextInputProps['value'], width?: ImageProps['width'] diff --git a/packages/react-strict-dom/tests/html/html-test.native.js b/packages/react-strict-dom/tests/html/html-test.native.js index 21981bc3..43850ade 100644 --- a/packages/react-strict-dom/tests/html/html-test.native.js +++ b/packages/react-strict-dom/tests/html/html-test.native.js @@ -253,6 +253,35 @@ describe(' (native polyfills)', () => { ); }); + test('"enterKeyHint" prop', () => { + const getProps = (element) => { + let root; + act(() => { + root = create(element); + }); + return root.root.children[0].props; + }; + const onKeyDown = () => {}; + // "next" with a keydown handler keeps focus on submit + const next = getProps( + + ); + expect(next.enterKeyHint).toBe('next'); + expect(next.submitBehavior).toBe('submit'); + // otherwise the React Native default is preserved + expect( + getProps().submitBehavior + ).toBeUndefined(); + expect( + getProps() + .submitBehavior + ).toBeUndefined(); + expect( + getProps() + .submitBehavior + ).toBeUndefined(); + }); + test('"tabIndex" prop', () => { let root; act(() => {