입력을 사용하는 데 문제가 있습니다 ... 두 개의 입력이 있습니다. 하나는 자동 초점이고 다른 하나는 입력하지 않습니다. 그러나 두 번째 입력을 입력하면 포커스가 사라지고 포커스는 첫 번째 입력으로 돌아갑니다.타이핑 할 때 입력이 흐려짐
나는 뭔가를 입력 할 때 React rerenders my component를 읽었다. 나는 열쇠 소품 등을 넣으려고했지만 아무 것도 효과가 없었습니다. 내 양식 (회원 가입라는 구성 요소)에서
, 나는 다음과 같은 한 :
import React, { PropTypes } from 'react'
import MaskedInput from 'react-maskedinput'
import styles from './styles.scss'
function Input (props) {
let iconComp
if (props.icon) {
iconComp = (<img src={props.icon} alt="Icon" />)
}
let input = ''
if (props.type === 'date') {
input = (
<MaskedInput
ref={inp => inp && props.autofocus && inp.focus()}
onChange={props.onChange}
mask="11/11/1111"
placeholder={props.placeholder}
className={styles.input}
/>
)
} else {
input = (
<input
ref={inp => inp && props.autofocus && inp.focus()}
onChange={props.onChange}
id={props.id}
placeholder={props.placeholder}
type={props.type}
className={styles.input}
/>
)
}
return (
<div className={styles.wrapper}>
<label htmlFor={props.id} className={styles.label}>{props.label}</label>
<br />
{input}
{props.error &&
<span className={styles.error}>
{props.errorMessage}
</span>
}
{iconComp}
</div>
)
}
Input.propTypes = {
id: PropTypes.string.isRequired,
label: PropTypes.string.isRequired,
icon: PropTypes.string,
placeholder: PropTypes.string,
type: PropTypes.string,
autofocus: PropTypes.bool,
onChange: PropTypes.func.isRequired,
error: PropTypes.bool,
errorMessage: PropTypes.string
}
Input.defaultProps = {
icon: '',
placeholder: '',
type: 'text',
autofocus: false,
error: false,
errorMessage: ''
}
export default Input
가 어떻게이 문제를 해결할 수 :
import React from 'react'
import Input from '../../components/Input'
import styles from './styles.scss'
class Signup extends React.Component {
constructor (props) {
super(props)
this.state = {
name: '',
email: '',
}
}
onSignup (e, userData) {
e.preventDefault()
this.props.onSignup(userData)
}
render() {
return (
<main className={styles.wrapper}>
<div className={styles.formSide}>
<h1>SIGNUP</h1>
<Input
id="name"
label="Name"
onChange={e => this.setState({ name: e.target.value })}
autofocus={true}
/>
<Input
id="email"
label="E-mail"
onChange={e => this.setState({ email: e.target.value })}
/>
</div>
</main>
)
}
}
Signup.propTypes = {
onSignup: React.PropTypes.func.isRequired
}
export default Signup
내 컴포넌트 입력이 코드가?
바이올린이나 플 런커에 넣을 수 있습니까? – floor
데모를 만들면 해결책이 있다고 생각하지만 테스트 할 수는 없습니다. – floor
http://codepen.io/anon/pen/EmKQqy – leonero