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 @@ -354,6 +354,9 @@ type IOSProps = $ReadOnly<{|
354354 /**
355355 * Give the keyboard and the system information about the
356356 * 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.
357360 * @platform ios
358361 */
359362 textContentType ?: ?TextContentType ,
@@ -1655,16 +1658,20 @@ const ExportedForwardRef: React.AbstractComponent<
16551658 }
16561659 autoComplete = {
16571660 Platform . OS === 'android'
1658- ? // $FlowFixMe
1661+ ? // $FlowFixMe[invalid-computed-prop]
1662+ // $FlowFixMe[prop-missing]
16591663 autoCompleteWebToAutoCompleteAndroidMap [ autoComplete ] ??
16601664 autoComplete
16611665 : undefined
16621666 }
16631667 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]
16681675 autoCompleteWebToTextContentTypeMap [ autoComplete ]
16691676 : textContentType
16701677 }
Original file line number Diff line number Diff line change @@ -169,6 +169,42 @@ describe('TextInput tests', () => {
169169 expect ( TextInput . State . currentlyFocusedInput ( ) ) . toBe ( textInputRe2 . current ) ;
170170 } ) ;
171171
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+
172208 it ( 'should render as expected' , ( ) => {
173209 expectRendersMatchingSnapshot (
174210 'TextInput' ,
Original file line number Diff line number Diff line change @@ -822,6 +822,13 @@ exports.examples = ([
822822 < WithLabel label = "name" >
823823 < TextInput textContentType = "name" style = { styles . default } />
824824 </ WithLabel >
825+ < WithLabel label = "postalCode, when autoComplete set" >
826+ < TextInput
827+ textContentType = "postalCode"
828+ autoComplete = "email"
829+ style = { styles . default }
830+ />
831+ </ WithLabel >
825832 </ View >
826833 ) ;
827834 } ,
You can’t perform that action at this time.
0 commit comments