File tree 3 files changed +55
-5
lines changed
Libraries/Components/TextInput
packages/rn-tester/js/examples/TextInput
3 files changed +55
-5
lines changed Original file line number Diff line number Diff line change @@ -354,6 +354,9 @@ type IOSProps = $ReadOnly<{|
354
354
/**
355
355
* Give the keyboard and the system information about the
356
356
* expected semantic meaning for the content that users enter.
357
+ * `autoComplete` property accomplishes same behavior and is recommended as its supported by both platforms.
358
+ * Avoid using both `autoComplete` and `textContentType`, you can use `Platform.select` for differing platform behaviors.
359
+ * For backwards compatibility, when both set, `textContentType` takes precedence on iOS.
357
360
* @platform ios
358
361
*/
359
362
textContentType ?: ?TextContentType ,
@@ -1655,16 +1658,20 @@ const ExportedForwardRef: React.AbstractComponent<
1655
1658
}
1656
1659
autoComplete = {
1657
1660
Platform . OS === 'android'
1658
- ? // $FlowFixMe
1661
+ ? // $FlowFixMe[invalid-computed-prop]
1662
+ // $FlowFixMe[prop-missing]
1659
1663
autoCompleteWebToAutoCompleteAndroidMap [ autoComplete ] ??
1660
1664
autoComplete
1661
1665
: undefined
1662
1666
}
1663
1667
textContentType = {
1664
- Platform . OS === 'ios' &&
1665
- autoComplete &&
1666
- autoComplete in autoCompleteWebToTextContentTypeMap
1667
- ? // $FlowFixMe
1668
+ textContentType != null
1669
+ ? textContentType
1670
+ : Platform . OS === 'ios' &&
1671
+ autoComplete &&
1672
+ autoComplete in autoCompleteWebToTextContentTypeMap
1673
+ ? // $FlowFixMe[invalid-computed-prop]
1674
+ // $FlowFixMe[prop-missing]
1668
1675
autoCompleteWebToTextContentTypeMap [ autoComplete ]
1669
1676
: textContentType
1670
1677
}
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 @@ -822,6 +822,13 @@ exports.examples = ([
822
822
< WithLabel label = "name" >
823
823
< TextInput textContentType = "name" style = { styles . default } />
824
824
</ WithLabel >
825
+ < WithLabel label = "postalCode, when autoComplete set" >
826
+ < TextInput
827
+ textContentType = "postalCode"
828
+ autoComplete = "email"
829
+ style = { styles . default }
830
+ />
831
+ </ WithLabel >
825
832
</ View >
826
833
) ;
827
834
} ,
You can’t perform that action at this time.
0 commit comments