1

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 :-

enter image description here

Can someone help me with this ?

1

5 Answers 5

4

You can simply use pointerEvents as "box-only" to disable the selection of entered value.

<TextInput pointerEvents="box-only" />.

Sign up to request clarification or add additional context in comments.

Comments

3

You can set attributes editable and selectTextOnFocus to false

Like:

<TextInput editable={false} selectTextOnFocus={false} />

Comments

2

Just set selection to the end of the text: selection={{start: this.state.text.length, end: this.state.text.length}}

1 Comment

although there is a jumping effect in android, this is the only that works
2

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}
      />
    );
  }
}

Comments

0

I think i have two Idea.

  1. You can try set in attribute selectTextOnFocus = "false" clearTextOnFocus = "true" from component TextInput:

  2. You can create a method to remove text with onChangeText if your TextInput is focus.

I hope my idea helping you...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.