r/reactnative • u/vaquishaProdigy • Oct 24 '26
Input not taking selectTextOnFocus
Made this component so i don't need to code it again in the scenes in which i need it, but in my Edit page i want to be able to copy and paste the text without losing the "editable={false}" atribute. I asked Copilot what can i do and i said i should use selectTextOnFocus but is not applying it so i just had to stick with this solution that doesn't really look professional.
Can i use selectTextOnFocus on this component or just stick to this solution?
The component code:
import React, { useState } from "react";
import { View, TextInput, TouchableOpacity } from "react-native";
import { psswrdInputStyles } from "./psswrdInputStyles";
import FontAwesome from "react-native-vector-icons/FontAwesome";
export default function PsswrdInput({
value,
editable,
placeholder,
}) {
const [secureText, setSecureText] = useState(true);
return (
<View style={psswrdInputStyles.passwordRow}>
<TextInput
style={[
psswrdInputStyles.input,
psswrdInputStyles.passwordInput,
]}
placeholder={placeholder}
placeholderTextColor="#9ca3af"
secureTextEntry={secureText}
value={value}
editable={editable}
/>
<TouchableOpacity
style={psswrdInputStyles.eyeBtn}
onPress={() => setSecureText((prev) => !prev)}
activeOpacity={0.7}
>
<FontAwesome
name={secureText ? "eye-slash" : "eye"}
size={20}
color="black"
/>
</TouchableOpacity>
</View>
);
}How i call it in the edit page:
<View style={editStyles.field}>
<Text style={editStyles.label}>Password</Text>
<PsswrdInput value={password} onChangeText={() => ({})} />
</View>
0
Upvotes
View all comments
Show parent comment
1
u/cylism-coding Oct 25 '26
No need to rewrite the whole component. You can keep the View, styles and eye toggle, and add a read-only branch: when editable === false, render Text instead of TextInput. Show a masked string while hidden, then <Text selectable>{value}</Text> when revealed (import Text from react-native). Keep TextInput for screens that allow editing.
Also, the usage you posted doesn't pass editable={false}, so pass that explicitly. Forwarding selectTextOnFocus and onChangeText would help the editable version, but won't by itself solve copying from a read-only, secure input. Test long-press copying on both Android and iOS.