File tree Expand file tree Collapse file tree 3 files changed +55
-5
lines changed
Libraries/Components/TextInput
packages/rn-tester/js/examples/TextInput Expand file tree Collapse file tree 3 files changed +55
-5
lines changed Original file line number Diff line number Diff line change @@ -349,6 +349,9 @@ type IOSProps = $ReadOnly<{|
349
349
/**
350
350
* Give the keyboard and the system information about the
351
351
* expected semantic meaning for the content that users enter.
352
+ * `autoComplete` property accomplishes same behavior and is recommended as its supported by both platforms.
353
+ * Avoid using both `autoComplete` and `textContentType`, you can use `Platform.select` for differing platform behaviors.
354
+ * For backwards compatibility, when both set, `textContentType` takes precedence on iOS.
352
355
* @platform ios
353
356
*/
354
357
textContentType ?: ?TextContentType ,
@@ -1630,16 +1633,20 @@ const ExportedForwardRef: React.AbstractComponent<
1630
1633
}
1631
1634
autoComplete = {
1632
1635
Platform . OS === 'android'
1633
- ? // $FlowFixMe
1636
+ ? // $FlowFixMe[invalid-computed-prop]
1637
+ // $FlowFixMe[prop-missing]
1634
1638
autoCompleteWebToAutoCompleteAndroidMap [ autoComplete ] ??
1635
1639
autoComplete
1636
1640
: undefined
1637
1641
}
1638
1642
textContentType = {
1639
- Platform . OS === 'ios' &&
1640
- autoComplete &&
1641
- autoComplete in autoCompleteWebToTextContentTypeMap
1642
- ? // $FlowFixMe
1643
+ textContentType != null
1644
+ ? textContentType
1645
+ : Platform . OS === 'ios' &&
1646
+ autoComplete &&
1647
+ autoComplete in autoCompleteWebToTextContentTypeMap
1648
+ ? // $FlowFixMe[invalid-computed-prop]
1649
+ // $FlowFixMe[prop-missing]
1643
1650
autoCompleteWebToTextContentTypeMap [ autoComplete ]
1644
1651
: textContentType
1645
1652
}
Original file line number Diff line number Diff line change @@ -169,6 +169,42 @@ describe('TextInput tests', () => {
169
169
expect ( TextInput . State . currentlyFocusedInput ( ) ) . toBe ( textInputRe2 . current ) ;
170
170
} ) ;
171
171
172
+ it ( 'should give precedence to `textContentType` when set' , ( ) => {
173
+ const instance = ReactTestRenderer . create (
174
+ < TextInput autoComplete = "tel" textContentType = "emailAddress" /> ,
175
+ ) ;
176
+
177
+ expect ( instance . toJSON ( ) ) . toMatchInlineSnapshot ( `
178
+ <RCTSinglelineTextInputView
179
+ accessible={true}
180
+ allowFontScaling={true}
181
+ focusable={true}
182
+ forwardedRef={null}
183
+ mostRecentEventCount={0}
184
+ onBlur={[Function]}
185
+ onChange={[Function]}
186
+ onChangeSync={null}
187
+ onClick={[Function]}
188
+ onFocus={[Function]}
189
+ onResponderGrant={[Function]}
190
+ onResponderMove={[Function]}
191
+ onResponderRelease={[Function]}
192
+ onResponderTerminate={[Function]}
193
+ onResponderTerminationRequest={[Function]}
194
+ onScroll={[Function]}
195
+ onSelectionChange={[Function]}
196
+ onSelectionChangeShouldSetResponder={[Function]}
197
+ onStartShouldSetResponder={[Function]}
198
+ rejectResponderTermination={true}
199
+ selection={null}
200
+ submitBehavior="blurAndSubmit"
201
+ text=""
202
+ textContentType="emailAddress"
203
+ underlineColorAndroid="transparent"
204
+ />
205
+ ` ) ;
206
+ } ) ;
207
+
172
208
it ( 'should render as expected' , ( ) => {
173
209
expectRendersMatchingSnapshot (
174
210
'TextInput' ,
Original file line number Diff line number Diff line change @@ -824,6 +824,13 @@ exports.examples = ([
824
824
< WithLabel label = "name" >
825
825
< TextInput textContentType = "name" style = { styles . default } />
826
826
</ WithLabel >
827
+ < WithLabel label = "postalCode, when autoComplete set" >
828
+ < TextInput
829
+ textContentType = "postalCode"
830
+ autoComplete = "email"
831
+ style = { styles . default }
832
+ />
833
+ </ WithLabel >
827
834
</ View >
828
835
) ;
829
836
} ,
You can’t perform that action at this time.
0 commit comments