Nie mogę automatycznie ustawić ostrości znacznika wejściowego renderowanego w tym komponencie. Czego tu mi brakuje?AutoFocus element wejściowy w celu reakcji JS
class TaskBox extends Component {
constructor() {
super();
this.focus = this.focus.bind(this);
}
focus() {
this.textInput.focus();
}
componentWillUpdate(){
this.focus();
}
render() {
let props = this.props;
return (
<div style={{display: props.visible ? 'block' : 'none'}}>
<input
ref={(input) => { this.textInput = input; }}
onBlur={props.blurFN} />
<div>
<div>Imp.</div>
<div>Urg.</div>
<div>Role</div>
</div>
<div>
<button>Add goal</button>
</div>
</div>
)
}
}
Każda pomoc jest doceniana.
Gdy jesteś renderowania bezstanową składnik, można po prostu dodać znak 'autoFocus' do elementu wejściowego i automatycznie ustawi ostrość w elemencie. –