Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions packages/react-strict-dom/src/types/renderer.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
29 changes: 29 additions & 0 deletions packages/react-strict-dom/tests/html/html-test.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,35 @@ describe('<html.*> (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(
<html.input enterKeyHint="next" onKeyDown={onKeyDown} />
);
expect(next.enterKeyHint).toBe('next');
expect(next.submitBehavior).toBe('submit');
// otherwise the React Native default is preserved
expect(
getProps(<html.input enterKeyHint="next" />).submitBehavior
).toBeUndefined();
expect(
getProps(<html.input enterKeyHint="done" onKeyDown={onKeyDown} />)
.submitBehavior
).toBeUndefined();
expect(
getProps(<html.textarea enterKeyHint="next" onKeyDown={onKeyDown} />)
.submitBehavior
).toBeUndefined();
});

test('"tabIndex" prop', () => {
let root;
act(() => {
Expand Down