Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all articles
Browse latest Browse all 28469

toLowerCase on TextInput value is creating duplicate text if capital letter created

$
0
0

This one's an interesting one.

I created a TextInput that takes a value, then lower cases it, adds it to state, and sets it as the default value. On my android physical device, if you force a capital letter ( autocapitalize is set to none), and then quickly tap other letters, it will duplicate and add extra text.

Is there a way to avoid this?

Here's a snack https://snack.expo.io/Hk1reKHJ4

Run it on your android or on the simulator, tap the upper case button on the keyboard, tap a few other letters, tap the upper case again, tap a few other letters, and you should set this error.

Thanks!

export default class App extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      text: ''
    }
  }
  render() {
    return (
      <View style={styles.container}>
        <TextInput
          style={ styles.inputContainer }
          defaultValue={ this.state.text }
          autoCapitalize="none"
          onChangeText={ value => this.setState({ 
            text: value.trim().toLowerCase()
            })}
        />
      </View>
    );
  }
}

Viewing all articles
Browse latest Browse all 28469

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>