I’m trying to style my TextInput placeholder with 2 colors so I’ve set it up in the following manner.
<TextInput
{ ...props }
style={[styles.textBox]}
>
{!value && required &&
<Text style={{ color: placeholderTextColor }}>
<Text style={{ color: 'red' }}>*</Text>
{placeholderText}
</Text>
}
</TextInput>
This looks fine for the most part but there are a few issues.
The cursor is placed at the end of the placehoderText. And when I type something it is appended to the placeholderText.
How do I stop the Text element inside the TextInput from being an active entity?
Edit
The props being sent are
{
placeholder={'Enter here'}
placeholderTextColor={'gray'}
autoCapitalize = 'sentences'
value={firstName}
maxLength= {15}
required={true}
returnKeyType="next"
onSubmitEditing={() => this._next ('lastName')}
onChangeText={(firstName) => updateFirstName ({ firstName }) }
}
2
Answers
Since I can’t comment, I’ll answer here instead!
Please provide more informations what’s in
{...props}
inside theTextInput
props. Make sure you didn’t give thevalue
prop the value ofplaceholderText
.The
Text
element that you have used inside theTextInput
is not aplaceholder
. It is an actual text that is being rendered on top of theTextInput
, which is why the cursor is appearing at the end of theplaceholderText
.Use the placeholder prop of the
TextInput
to set theplaceholder
text, and use theplaceholderTextColor
prop to set the color of the placeholder text. Then you can use the style prop to apply any additional stylingHere’s an updated version of your code: