react-native: TextInput clear() doesn't work at v0.54.2
When I use TextInput as a uncontrolled component, clear() method doesn’t work at all. Then I try the version at V0.52.2, everything goes fine
Environment
Environment: OS: macOS Sierra 10.12.6 Node: 8.9.4 Yarn: 0.24.6 npm: 5.6.0 Watchman: 4.9.0 Xcode: Xcode 9.2 Build version 9C40b Android Studio: 3.0 AI-171.4443003
Packages: (wanted => installed) react: ^16.3.0-alpha.1 => 16.3.0-alpha.1 react-native: ^0.54.2 => 0.54.2
Steps to Reproduce
import React, { Component } from 'react'
import { TextInput,StyleSheet, View } from 'react-native'
export default class TextInputDemo extends Component {
render() {
return (
<View style={styles.wrapper}>
<TextInput
ref="demo"
style={styles.formInput}
placeholder="I am placeholder..."
onChange={e => {}}
returnKeyType="send"
onSubmitEditing={() => {
this.refs.demo.clear()
}}
/>
</View>
)
}
}
const styles = StyleSheet.create({
wrapper: {
flex: 1,
backgroundColor: '#f7f7f7',
justifyContent: 'center',
padding: 30
},
formInput: {
height: 50,
backgroundColor: '#ffffff'
}
})
Expected Behavior
Something wrong with TextInput re-implement?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 14
- Comments: 24 (3 by maintainers)
@charpeni, on RN version 0.55.4 The defect is still reproduce. clear does not work in iOS
I’m using this:
I had this problem too. But found out that using value={this.state.myValue} will clear it.
Add Ref. to your textInput Like: <TextInput ref={input => { this.textInput = input }} /> And Call this.textInput.clear() to clear your input field.
I am having the same issue as .clear() and setState({input: ‘’}) do not work.
Try
this.refs[textInput]._root.clear()
. I’m using Native Base’s Input component and I realized theclear()
function got put into the_root
object. Hopefully that fixes it for some people.That’s the point, I’ve provided a reproducible example on Snack instead of plain text.
You can run this Snack on an older expo SDK version, everything will be fine.
same issue to me. I just init an entire new React Native app, no require any other third package.
Environment
the code in App.js:
what’s wrong ?Are you guys all OK ?