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(() => {