Home > Blockchain >  How select text in TextInput in react native for andorid?
How select text in TextInput in react native for andorid?

Time:06-14

How can I select all text in the TextInput field when I click on this field, i.e. the onFocus action?

CodePudding user response:

Pass selectTextOnFocus as a prop with TextInput. This will ensure that all text inside the TextInput is highlighted when the field is focused.

<TextInput ref={input => this.myInput = input} selectTextOnFocus style={{height: 100, width: 100}} defaultValue='Hey there' />

Usage to focus the TextInput: this.myInput.focus()


More Information : https://reactnative.dev/docs/textinput#selecttextonfocus

CodePudding user response:

You can use the selection prop of TextInput

<TextInput 
  value={'aaaa'}
  onFocus={onFocus}
  selection={{
    start: 0,
    end: 4,
  }}
/>

You can modify the start and end value onFocus. Reference: https://reactnative.dev/docs/textinput#selection

  • Related