TextField
An enhanced customizable TextField with validation support
(code example)
info
This component extends TextInput props.
tip
This component support margin, color, typography modifiers.
#
Usage<TextField placeholder={'Placeholder'} floatingPlaceholder onChangeText={onChangeText} enableErrors validate={['required', 'email', (value) => value.length > 6]} validationMessage={['Field is required', 'Email is invalid', 'Password is too short']} showCharCounter maxLength={30}/>
#
API#
centeredWhether to center the TextField - container and label
boolean
#
charCounterStylePass custom style to character counter text
TextStyle
#
colorInput color
ColorType
#
containerPropsContainer props of the whole component
Omit<ViewProps, 'style'>
#
containerStyleContainer style of the whole component
ViewStyle
#
enableErrorsShould support showing validation error message
boolean
#
fieldStyleInternal style for the field container to style the field underline, outline and fill color
ViewStyle | (context: FieldContextType, props) => ViewStyle
#
floatOnFocusShould placeholder float on focus or when start typing
boolean
#
floatingPlaceholderPass to add floating placeholder support
boolean
#
floatingPlaceholderColorThe floating placeholder color
ColorType
#
floatingPlaceholderStyleCustom style for the floating placeholder
TextStyle
#
formatterCustom formatter for the input value (used only when input if not focused)
(value) => string | undefined
#
hintA hint text to display when focusing the field
string
#
labelField label
string
#
labelColorField label color. Either a string or color by state map ({default, focus, error, disabled, readonly})
ColorType
#
labelPropsPass extra props to the label Text element
TextProps
#
labelStyleCustom style for the field label
TextStyle
#
leadingAccessoryPass to render a leading element
ReactElement
#
onChangeValidityCallback for when field validity has changed
(isValid: boolean) => void
#
onValidationFailedCallback for when field validated and failed
(failedValidatorIndex: number) => void
#
placeholderThe placeholder for the field
string
#
placeholderTextColorPlaceholder text color
ColorType
#
presetPredefined preset to use for styling the field
'default' | null | string
#
readonlyA UI preset for read only state
boolean
#
recorderTagRecorder Tag
'mask' | 'unmask'
#
retainValidationSpaceKeep the validation space even if there is no validation message
boolean
#
showCharCounterShould show a character counter (works only with maxLength)
boolean
#
showMandatoryIndicationWhether to show a mandatory field indication
boolean
#
trailingAccessoryPass to render a trailing element
ReactElement
#
useGestureHandlerInputUse react-native-gesture-handler instead of react-native for the base TextInput
boolean
#
validateA single or multiple validator. Can be a string (required, email) or custom function.
Validator | Validator[]
#
validateOnBlurShould validate when losing focus of TextField
boolean
#
validateOnChangeShould validate when the TextField value changes
boolean
#
validateOnStartShould validate when the TextField mounts
boolean
#
validationMessageThe validation message to display when field is invalid (depends on validate)
string | string[]
#
validationMessagePositionThe position of the validation message (top/bottom)
ValidationMessagePosition
#
validationMessageStyleCustom style for the validation message
TextStyle