Answer the question
In order to leave comments, you need to log in
Why is onChange not working on a text field on iOS?
There was a problem when working with inputs on iOS.
Here is my component code:
import './Input.css'
import {
Component
} from 'react'
export default class Input extends Component {
constructor(props) {
super(props);
this.state = {
value: this.props.content,
initiate: this.props.content,
errored: false
}
this.handleChange = this.handleChange.bind(this)
}
handleChange(event) {
this.setState({
value: event.target.value
}, () => {
if (this.props.callback) {
this.props.callback(this)
}
})
}
render() {
if (this.props.content !== this.state.initiate) {
this.setState({
value: this.props.content,
initiate: this.props.content
})
}
return ( <
> {
this.props.label ? < label htmlFor = {
this.props.type
} > {
this.props.label
} : < /label> : null} <
input onBlur = {
this.props.onBlur
}
onFocus = {
this.props.onFocus
}
type = {
this.props.type === 'password' ? 'password' : 'text'
}
className = {
'Input' + (this.state.errored ? ' Input_errored' : '')
}
id = {
this.props.type
}
placeholder = {
this.props.placeholder
}
data - name = {
this.props.type
}
value = {
this.state.value || ''
}
disabled = {
this.props.disabled
}
onChange = {
this.handleChange
}
/> <
/>
)
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question