Reputation: 1324
I have a Text Input that I am using in React Native and want to disable Text Selection and further options that are show in the image :-
Can someone help me with this ?
Upvotes: 1
Views: 14168
Reputation: 933
You can simply use pointerEvents
as "box-only"
to disable the selection of entered value.
<TextInput pointerEvents="box-only" />
.
Upvotes: 4
Reputation: 21
You can use selection property. And when selection change, set selection prop to end position of your selection.
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
selection: { start: 0, end: 0 },
};
}
onSelectionChange = ({ nativeEvent: { selection, text } }) => {
this.setState({ selection: { start: selection.end, end: selection.end } });
};
render() {
return (
<TextInput
onSelectionChange={this.onSelectionChange}
selection={this.state.selection}
value={this.state.value}
/>
);
}
}
Upvotes: 2
Reputation: 820
I think i have two Idea.
You can try set in attribute selectTextOnFocus
= "false" clearTextOnFocus
= "true" from component TextInput
:
You can create a method to remove text with onChangeText if your TextInput is focus.
I hope my idea helping you...
Upvotes: 0
Reputation: 444
Just set selection to the end of the text: selection={{start: this.state.text.length, end: this.state.text.length}}
Upvotes: 2
Reputation: 9206
You can set attributes editable and selectTextOnFocus to false
Like:
<TextInput editable={false} selectTextOnFocus={false} />
Upvotes: 3