I have a TextInput field with placeholder given. On load the placeholder text should be shown as fontWeight:"normal"
and when the user enters a value in textbox - the letter gets in fontWeight:"bold"
but when the textbox is again empty - the placeholder should revert to fontWeight:"normal"
. Currently, despite changing and updating the state, the placeholder still takes "fontWeight:bold"
, once the user types and removes the text from TextInput field.
I tried using placeholderStyle, but this is not for my scenario, I dont want to change the style, only font weight.
<TextInput
style={
!searchText
? [styles.autoCompleteInputStyle, styles.placeholderText]
: [styles.autoCompleteInputStyle, styles.searchedText]
}
underlineColorAndroid="transparent"
placeholder="Search item"
placeholderTextColor="#505050"
autocorrect={false}
value={searchText}
onChangeText={searchTextValue => this.onChangeText(searchTextValue)}
clearButtonMode="while-editing"
returnKeyType="search"
/>
Style for autocompleteTextInput
autoCompleteInputStyle: {
flexDirection: "row",
height: 40,
borderStyle: "solid",
borderWidth: 1,
borderColor: "#cccccc",
fontSize: 18,
flex: 1,
justifyContent: "center",
marginRight: 14,
marginBottom: 20,
paddingLeft: 40,
color: "#000000",
borderRadius: 2,
lineHeight: 21,
fontFamily: fontStyleFlightCard.fontFamily
},
searchedText: {
fontWeight: "bold"
},
placeholderText: {
fontWeight: "normal"
},
I expect placeholder should be in normal fontWeight, and when the user inputs text, it should be in bold. Whenever the user types and removes the text from TextInput, placeholder text changes to normal fontWeight.