TextInput - focusable but not editable
See original GitHub issueIs your feature request related to a problem? Please describe.
A TextInput can be disabled={true}
(grey text, no focus, no edit), and it can be editable={false}
(normal color text, no focus, no edit). However, it would be very handy to allow focus while still not allowing editable.
Why? Because if the text is focusable, then it can be highlighted & copied to the clipboard (via standard OS capabilities).
Describe the solution you’d like
Either make editable={false}
allow focus, but not edit; or add a new setting to support as described above (focus but not edit).
Describe alternatives you’ve considered I have a TextInput with a onChangeText that simply returns the initial value passed into the component:
const myFocusableTextInput = ({initValue, label, mode}) => {
const [text, setText] = useState(initValue);
return (
<TextInput label={label} value={text} mode={mode} onChangeText={(v) => setText(initValue)} />
);
}
expo: 38.0.8 @expo/vector-icons 10.2.0 react-native: 0.62.2 react-native-paper: 4.0.1
Issue Analytics
- State:
- Created 3 years ago
- Reactions:8
- Comments:7 (1 by maintainers)
Top GitHub Comments
Another use case for this would be supporting a date picker input that should display a static (non-editable value) as well as a calendar icon. Pressing the right icon (calendar) can open the date picker dialog and should focus the field (to trigger validation on previous field, etc).
This is only possible currently by using
editable={true}
(ie. normal) and then passing in a value and setting `onChangeText={() => {}). However, this still can “allow” the user to appear to edit the field, although changes are immediately replaced with static value.The workaround I listed above is … not a good UX. It is possible to wind up with weird behaviours based on timing issues because the control is actually allowing the user to interact with the value…it just overwrites what the user does with the initial value. Not a good solution.
Thanks for the ping @kendallroth !