Skip to content
Closed
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
39 changes: 39 additions & 0 deletions Libraries/Components/TextInput/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,15 @@ export type TextContentType =
| 'newPassword'
| 'oneTimeCode';

export type enterKeyHintType =
| 'enter'
| 'done'
| 'go'
| 'next'
| 'previous'
| 'search'
| 'send';

type PasswordRules = string;

type IOSProps = $ReadOnly<{|
Expand Down Expand Up @@ -536,6 +545,21 @@ export type Props = $ReadOnly<{|
React.ElementRef<HostComponent<mixed>> & ImperativeMethods,
>,

/**
* `enterKeyHint` defines what action label (or icon) to present for the enter key on virtual keyboards.
*
* The following values is supported:
*
* - `enter`
* - `done`
* - `go`
* - `next`
* - `previous`
* - `search`
* - `send`
*/
enterKeyHint?: ?enterKeyHintType,

/**
* Determines which keyboard to open, e.g.`numeric`.
*
Expand Down Expand Up @@ -1380,6 +1404,16 @@ function InternalTextInput(props: Props): React.Node {
);
}

const enterKeyHintToReturnTypeMap = {
enter: 'default',
done: 'done',
go: 'go',
next: 'next',
previous: 'previous',
search: 'search',
send: 'send',
};

const ExportedForwardRef: React.AbstractComponent<
React.ElementConfig<typeof InternalTextInput>,
React.ElementRef<HostComponent<mixed>> & ImperativeMethods,
Expand All @@ -1390,6 +1424,8 @@ const ExportedForwardRef: React.AbstractComponent<
underlineColorAndroid = 'transparent',
readOnly,
editable,
enterKeyHint,
returnKeyType,
...restProps
},
forwardedRef: ReactRefSetter<
Expand All @@ -1402,6 +1438,9 @@ const ExportedForwardRef: React.AbstractComponent<
rejectResponderTermination={rejectResponderTermination}
underlineColorAndroid={underlineColorAndroid}
editable={readOnly !== undefined ? !readOnly : editable}
returnKeyType={
enterKeyHint ? enterKeyHintToReturnTypeMap[enterKeyHint] : returnKeyType
}
{...restProps}
forwardedRef={forwardedRef}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,29 @@ module.exports = ([
return <BlurOnSubmitExample />;
},
},
{
title: 'enterKeyHint modes',
name: 'enterKeyHintTypes',
render: function (): React.Node {
const enterKeyHintTypesHints = [
'enter',
'done',
'go',
'next',
'previous',
'search',
'send',
];
const examples = enterKeyHintTypesHints.map(hint => {
return (
<WithLabel key={hint} label={hint}>
<TextInput enterKeyHint={hint} style={styles.default} />
</WithLabel>
);
});
return <View>{examples}</View>;
},
},
{
title: 'Submit behavior',
render: function (): React.Element<any> {
Expand Down