Kim HanSol
Kim HanSol

Reputation: 33

React Native Textinput NumberOfLines property issue

version "react": "16.11.0", "react-native": "0.62.2",

https://reactnative.dev/docs/textinput#numberoflines

If you look at the React Native documents, This feature is available.

this my code

enter image description here

But, not working

enter image description here

How can limit the lines?

Upvotes: 0

Views: 1185

Answers (1)

Djellal Mohamed Aniss
Djellal Mohamed Aniss

Reputation: 1733

maybe the the property doesn't set a maximum number of lines, but here's an alternative

// set the max lines

const MAX_LINES = 3


// method to handle the text change
onTextFieldChange = (text) => {
   if (  text.split(/\r\n|\r|\n/).length <= MAX_LINES ) 
   {
      this.setState({text});
   }
}


// on your textInput
<TextInput
   // properties...
   onTextChange={this.onTextInputChange}
/>

Upvotes: 2

Related Questions