... and different keyboard types, such as a numeric keypad. ... Note that on Android performing text selection in an input can change the ...
SkiptomaincontentReactNative0.66Next0.660.650.640.630.620.610.60AllversionsDocsComponentsAPICommunityBlog🌜🌞SearchOnthispageAfoundationalcomponentforinputtingtextintotheappviaakeyboard.Propsprovideconfigurabilityforseveralfeatures,suchasauto-correction,auto-capitalization,placeholdertext,anddifferentkeyboardtypes,suchasanumerickeypad.ThemostbasicusecaseistoplopdownaTextInputandsubscribetotheonChangeTexteventstoreadtheuserinput.Therearealsootherevents,suchasonSubmitEditingandonFocusthatcanbesubscribedto.Aminimalexample:Twomethodsexposedviathenativeelementare.focus()and.blur()thatwillfocusorblurtheTextInputprogrammatically.Notethatsomepropsareonlyavailablewithmultiline={true/false}.Additionally,borderstylesthatapplytoonlyonesideoftheelement(e.g.,borderBottomColor,borderLeftWidth,etc.)willnotbeappliedifmultiline=true.Toachievethesameeffect,youcanwrapyourTextInputinaView:TextInputhasbydefaultaborderatthebottomofitsview.Thisborderhasitspaddingsetbythebackgroundimageprovidedbythesystem,anditcannotbechanged.Solutionstoavoidthisaretoeithernotsetheightexplicitly,inwhichcasethesystemwilltakecareofdisplayingtheborderinthecorrectposition,ortonotdisplaytheborderbysettingunderlineColorAndroidtotransparent.NotethatonAndroidperformingtextselectioninaninputcanchangetheapp'sactivitywindowSoftInputModeparamtoadjustResize.Thismaycauseissueswithcomponentsthathaveposition:'absolute'whilethekeyboardisactive.ToavoidthisbehavioreitherspecifywindowSoftInputModeinAndroidManifest.xml(https://developer.android.com/guide/topics/manifest/activity-element.html)orcontrolthisparamprogrammaticallywithnativecode.PropsViewPropsInheritsViewProps.allowFontScalingSpecifieswhetherfontsshouldscaletorespectTextSizeaccessibilitysettings.Thedefaultistrue.TypeboolautoCapitalizeTellsTextInputtoautomaticallycapitalizecertaincharacters.Thispropertyisnotsupportedbysomekeyboardtypessuchasname-phone-pad.characters:allcharacters.words:firstletterofeachword.sentences:firstletterofeachsentence(default).none:don'tautocapitalizeanything.Typeenum('none','sentences','words','characters')autoCompleteAndroidSpecifiesautocompletehintsforthesystem,soitcanprovideautofill.OnAndroid,thesystemwillalwaysattempttoofferautofillbyusingheuristicstoidentifythetypeofcontent.Todisableautocomplete,setautoCompletetooff.PossiblevaluesforautoCompleteare:birthdate-daybirthdate-fullbirthdate-monthbirthdate-yearcc-csccc-expcc-exp-daycc-exp-monthcc-exp-yearcc-numberemailgendernamename-familyname-givenname-middlename-middle-initialname-prefixname-suffixpasswordpassword-newpostal-addresspostal-address-countrypostal-address-extendedpostal-address-extended-postal-codepostal-address-localitypostal-address-regionpostal-codestreet-addresssms-otpteltel-country-codetel-nationaltel-deviceusernameusername-newoffTypeenum('birthdate-day','birthdate-full','birthdate-month','birthdate-year','cc-csc','cc-exp','cc-exp-day','cc-exp-month','cc-exp-year','cc-number','email','gender','name','name-family','name-given','name-middle','name-middle-initial','name-prefix','name-suffix','password','password-new','postal-address','postal-address-country','postal-address-extended','postal-address-extended-postal-code','postal-address-locality','postal-address-region','postal-code','street-address','sms-otp','tel','tel-country-code','tel-national','tel-device','username','username-new','off')autoCorrectIffalse,disablesauto-correct.Thedefaultvalueistrue.TypeboolautoFocusIftrue,focusestheinputoncomponentDidMountoruseEffect.Thedefaultvalueisfalse.TypeboolblurOnSubmitIftrue,thetextfieldwillblurwhensubmitted.Thedefaultvalueistrueforsingle-linefieldsandfalseformultilinefields.Notethatformultilinefields,settingblurOnSubmittotruemeansthatpressingreturnwillblurthefieldandtriggertheonSubmitEditingeventinsteadofinsertinganewlineintothefield.TypeboolcaretHiddenIftrue,caretishidden.Thedefaultvalueisfalse.TypeboolclearButtonModeiOSWhentheclearbuttonshouldappearontherightsideofthetextview.Thispropertyissupportedonlyforsingle-lineTextInputcomponent.Thedefaultvalueisnever.Typeenum('never','while-editing','unless-editing','always')clearTextOnFocusiOSIftrue,clearsthetextfieldautomaticallywheneditingbegins.TypeboolcontextMenuHiddenIftrue,contextmenuishidden.Thedefaultvalueisfalse.TypebooldataDetectorTypesiOSDeterminesthetypesofdataconvertedtoclickableURLsinthetextinput.Onlyvalidifmultiline={true}andeditable={false}.Bydefaultnodatatypesaredetected.Youcanprovideonetypeoranarrayofmanytypes.PossiblevaluesfordataDetectorTypesare:'phoneNumber''link''address''calendarEvent''none''all'Typeenum('phoneNumber','link','address','calendarEvent','none','all'),,arrayofenum('phoneNumber','link','address','calendarEvent','none','all')defaultValueProvidesaninitialvaluethatwillchangewhentheuserstartstyping.Usefulforuse-caseswhereyoudonotwanttodealwithlisteningtoeventsandupdatingthevalueproptokeepthecontrolledstateinsync.TypestringdisableFullscreenUIAndroidWhenfalse,ifthereisasmallamountofspaceavailablearoundatextinput(e.g.landscapeorientationonaphone),theOSmaychoosetohavetheusereditthetextinsideofafullscreentextinputmode.Whentrue,thisfeatureisdisabledanduserswillalwayseditthetextdirectlyinsideofthetextinput.Defaultstofalse.TypebooleditableIffalse,textisnoteditable.Thedefaultvalueistrue.TypeboolenablesReturnKeyAutomaticallyiOSIftrue,thekeyboarddisablesthereturnkeywhenthereisnotextandautomaticallyenablesitwhenthereistext.Thedefaultvalueisfalse.TypeboolimportantForAutofillAndroidTellstheoperatingsystemwhethertheindividualfieldsinyourappshouldbeincludedinaviewstructureforautofillpurposesonAndroidAPILevel26+.Possiblevaluesareauto,no,noExcludeDescendants,yes,andyesExcludeDescendants.Thedefaultvalueisauto.auto:LettheAndroidSystemuseitsheuristicstodetermineiftheviewisimportantforautofill.no:Thisviewisn'timportantforautofill.noExcludeDescendants:Thisviewanditschildrenaren'timportantforautofill.yes:Thisviewisimportantforautofill.yesExcludeDescendants:Thisviewisimportantforautofill,butitschildrenaren'timportantforautofill.Typeenum('auto','no','noExcludeDescendants','yes','yesExcludeDescendants')inlineImageLeftAndroidIfdefined,theprovidedimageresourcewillberenderedontheleft.Theimageresourcemustbeinside/android/app/src/main/res/drawableandreferencedlikeCopyTypestringinlineImagePaddingAndroidPaddingbetweentheinlineimage,ifany,andthetextinputitself.TypenumberinputAccessoryViewIDiOSAnoptionalidentifierwhichlinksacustomInputAccessoryViewtothistextinput.TheInputAccessoryViewisrenderedabovethekeyboardwhenthistextinputisfocused.TypestringkeyboardAppearanceiOSDeterminesthecolorofthekeyboard.Typeenum('default','light','dark')keyboardTypeDetermineswhichkeyboardtoopen,e.g.numeric.Seescreenshotsofallthetypeshere.Thefollowingvaluesworkacrossplatforms:defaultnumber-paddecimal-padnumericemail-addressphone-padiOSOnlyThefollowingvaluesworkoniOSonly:ascii-capablenumbers-and-punctuationurlname-phone-padtwitterweb-searchAndroidOnlyThefollowingvaluesworkonAndroidonly:visible-passwordTypeenum('default','email-address','numeric','phone-pad','ascii-capable','numbers-and-punctuation','url','number-pad','name-phone-pad','decimal-pad','twitter','web-search','visible-password')maxFontSizeMultiplierSpecifieslargestpossiblescaleafontcanreachwhenallowFontScalingisenabled.Possiblevalues:null/undefined(default):inheritfromtheparentnodeortheglobaldefault(0)0:nomax,ignoreparent/globaldefault>=1:setsthemaxFontSizeMultiplierofthisnodetothisvalueTypenumbermaxLengthLimitsthemaximumnumberofcharactersthatcanbeentered.UsethisinsteadofimplementingthelogicinJStoavoidflicker.TypenumbermultilineIftrue,thetextinputcanbemultiplelines.Thedefaultvalueisfalse.ItisimportanttonotethatthisalignsthetexttothetoponiOS,andcentersitonAndroid.UsewithtextAlignVerticalsettotopforthesamebehaviorinbothplatforms.TypeboolnumberOfLinesAndroidSetsthenumberoflinesforaTextInput.Useitwithmultilinesettotruetobeabletofillthelines.TypenumberonBlurCallbackthatiscalledwhenthetextinputisblurred.Note:IfyouareattemptingtoaccessthetextvaluefromnativeEventkeepinmindthattheresultingvalueyougetcanbeundefinedwhichcancauseunintendederrors.IfyouaretryingtofindthelastvalueofTextInput,youcanusetheonEndEditingevent,whichisfireduponcompletionofediting.TypefunctiononChangeCallbackthatiscalledwhenthetextinput'stextchanges.Type({nativeEvent:{eventCount,target,text}})=>voidonChangeTextCallbackthatiscalledwhenthetextinput'stextchanges.Changedtextispassedasasinglestringargumenttothecallbackhandler.TypefunctiononContentSizeChangeCallbackthatiscalledwhenthetextinput'scontentsizechanges.Onlycalledformultilinetextinputs.Type({nativeEvent:{contentSize:{width,height}}})=>voidonEndEditingCallbackthatiscalledwhentextinputends.TypefunctiononPressInCallbackthatiscalledwhenatouchisengaged.Type({nativeEvent:PressEvent})=>voidonPressOutCallbackthatiscalledwhenatouchisreleased.Type({nativeEvent:PressEvent})=>voidonFocusCallbackthatiscalledwhenthetextinputisfocused.Type({nativeEvent:LayoutEvent})=>voidonKeyPressCallbackthatiscalledwhenakeyispressed.ThiswillbecalledwithobjectwherekeyValueis'Enter'or'Backspace'forrespectivekeysandthetyped-incharacterotherwiseincluding''forspace.FiresbeforeonChangecallbacks.Note:onAndroidonlytheinputsfromsoftkeyboardarehandled,notthehardwarekeyboardinputs.Type({nativeEvent:{key:keyValue}})=>voidonLayoutInvokedonmountandonlayoutchanges.Type({nativeEvent:LayoutEvent})=>voidonScrollInvokedoncontentscroll.MayalsocontainotherpropertiesfromScrollEventbutonAndroidcontentSizeisnotprovidedforperformancereasons.Type({nativeEvent:{contentOffset:{x,y}}})=>voidonSelectionChangeCallbackthatiscalledwhenthetextinputselectionischanged.Type({nativeEvent:{selection:{start,end}}})=>voidonSubmitEditingCallbackthatiscalledwhenthetextinput'ssubmitbuttonispressed.Type({nativeEvent:{text,eventCount,target}})=>voidNotethatoniOSthismethodisn'tcalledwhenusingkeyboardType="phone-pad".placeholderThestringthatwillberenderedbeforetextinputhasbeenentered.TypestringplaceholderTextColorThetextcoloroftheplaceholderstring.TypecolorreturnKeyLabelAndroidSetsthereturnkeytothelabel.UseitinsteadofreturnKeyType.TypestringreturnKeyTypeDetermineshowthereturnkeyshouldlook.OnAndroidyoucanalsousereturnKeyLabel.CrossplatformThefollowingvaluesworkacrossplatforms:donegonextsearchsendAndroidOnlyThefollowingvaluesworkonAndroidonly:nonepreviousiOSOnlyThefollowingvaluesworkoniOSonly:defaultemergency-callgooglejoinrouteyahooTypeenum('done','go','next','search','send','none','previous','default','emergency-call','google','join','route','yahoo')rejectResponderTerminationiOSIftrue,allowsTextInputtopasstoucheventstotheparentcomponent.ThisallowscomponentssuchasSwipeableListViewtobeswipeablefromtheTextInputoniOS,asisthecaseonAndroidbydefault.Iffalse,TextInputalwaysaskstohandletheinput(exceptwhendisabled).Thedefaultvalueistrue.TypeboolscrollEnablediOSIffalse,scrollingofthetextviewwillbedisabled.Thedefaultvalueistrue.Onlyworkswithmultiline={true}.TypeboolsecureTextEntryIftrue,thetextinputobscuresthetextenteredsothatsensitivetextlikepasswordsstaysecure.Thedefaultvalueisfalse.Doesnotworkwithmultiline={true}.TypeboolselectionThestartandendofthetextinput'sselection.Setstartandendtothesamevaluetopositionthecursor.Typeobject:{start:number,end:number}selectionColorThehighlightandcursorcolorofthetextinput.TypecolorselectTextOnFocusIftrue,alltextwillautomaticallybeselectedonfocus.TypeboolshowSoftInputOnFocusWhenfalse,itwillpreventthesoftkeyboardfromshowingwhenthefieldisfocused.Thedefaultvalueistrue.TypeboolspellCheckiOSIffalse,disablesspell-checkstyle(i.e.redunderlines).ThedefaultvalueisinheritedfromautoCorrect.TypebooltextAlignAligntheinputtexttotheleft,center,orrightsidesoftheinputfield.PossiblevaluesfortextAlignare:leftcenterrightTypeenum('left','center','right')textContentTypeiOSGivethekeyboardandthesysteminformationabouttheexpectedsemanticmeaningforthecontentthatusersenter.ForiOS11+youcansettextContentTypetousernameorpasswordtoenableautofilloflogindetailsfromthedevicekeychain.ForiOS12+newPasswordcanbeusedtoindicateanewpasswordinputtheusermaywanttosaveinthekeychain,andoneTimeCodecanbeusedtoindicatethatafieldcanbeautofilledbyacodearrivinginanSMS.Todisableautofill,settextContentTypetonone.PossiblevaluesfortextContentTypeare:noneURLaddressCityaddressCityAndStateaddressStatecountryNamecreditCardNumberemailAddressfamilyNamefullStreetAddressgivenNamejobTitlelocationmiddleNamenamenamePrefixnameSuffixnicknameorganizationNamepostalCodestreetAddressLine1streetAddressLine2sublocalitytelephoneNumberusernamepasswordnewPasswordoneTimeCodeTypeenum('none','URL','addressCity','addressCityAndState','addressState','countryName','creditCardNumber','emailAddress','familyName','fullStreetAddress','givenName','jobTitle','location','middleName','name','namePrefix','nameSuffix','nickname','organizationName','postalCode','streetAddressLine1','streetAddressLine2','sublocality','telephoneNumber','username','password')passwordRulesiOSWhenusingtextContentTypeasnewPasswordoniOSwecanlettheOSknowtheminimumrequirementsofthepasswordsothatitcangenerateonethatwillsatisfythem.InordertocreateavalidstringforPasswordRulestakealooktotheAppleDocs.Ifpasswordsgenerationdialogdoesn'tappearpleasemakesurethat:AutoFillisenabled:Settings→Passwords&Accounts→toggle"On"theAutoFillPasswords,iCloudKeychainisused:Settings→AppleID→iCloud→Keychain→toggle"On"theiCloudKeychain.TypestringstyleNotethatnotallTextstylesaresupported,anincompletelistofwhatisnotsupportedincludes:borderLeftWidthborderTopWidthborderRightWidthborderBottomWidthborderTopLeftRadiusborderTopRightRadiusborderBottomRightRadiusborderBottomLeftRadiusseeIssue#7070formoredetail.StylesTypeTexttextBreakStrategyAndroidSettextbreakstrategyonAndroidAPILevel23+,possiblevaluesaresimple,highQuality,balancedThedefaultvalueissimple.Typeenum('simple','highQuality','balanced')underlineColorAndroidAndroidThecoloroftheTextInputunderline.TypecolorvalueThevaluetoshowforthetextinput.TextInputisacontrolledcomponent,whichmeansthenativevaluewillbeforcedtomatchthisvaluepropifprovided.Formostuses,thisworksgreat,butinsomecasesthismaycauseflickering-onecommoncauseispreventingeditsbykeepingvaluethesame.Inadditiontosettingthesamevalue,eitherseteditable={false},orset/updatemaxLengthtopreventunwantededitswithoutflicker.TypestringMethods.focus()focus();CopyMakesthenativeinputrequestfocus..blur()blur();CopyMakesthenativeinputlosefocus.clear()clear();CopyRemovesalltextfromtheTextInput.isFocused()isFocused();CopyReturnstrueiftheinputiscurrentlyfocused;falseotherwise.react-native#19096:Doesn'tsupportAndroid'sonKeyPreIme.react-native#19366:Calling.focus()afterclosingAndroid'skeyboardviabackbuttondoesn'tbringkeyboardupagain.react-native#26799:Doesn'tsupportAndroid'ssecureTextEntrywhenkeyboardType="email-address"orkeyboardType="phone-pad".Previous«TextNextTouchableHighlight»PropsViewPropsallowFontScalingautoCapitalizeautoCompleteAndroidautoCorrectautoFocusblurOnSubmitcaretHiddenclearButtonModeiOSclearTextOnFocusiOScontextMenuHiddendataDetectorTypesiOSdefaultValuedisableFullscreenUIAndroideditableenablesReturnKeyAutomaticallyiOSimportantForAutofillAndroidinlineImageLeftAndroidinlineImagePaddingAndroidinputAccessoryViewIDiOSkeyboardAppearanceiOSkeyboardTypemaxFontSizeMultipliermaxLengthmultilinenumberOfLinesAndroidonBluronChangeonChangeTextonContentSizeChangeonEndEditingonPressInonPressOutonFocusonKeyPressonLayoutonScrollonSelectionChangeonSubmitEditingplaceholderplaceholderTextColorreturnKeyLabelAndroidreturnKeyTyperejectResponderTerminationiOSscrollEnablediOSsecureTextEntryselectionselectionColorselectTextOnFocusshowSoftInputOnFocusspellCheckiOStextAligntextContentTypeiOSpasswordRulesiOSstyletextBreakStrategyAndroidunderlineColorAndroidAndroidvalueMethods.focus().blur()clear()isFocused()