Answer the question
In order to leave comments, you need to log in
When clicking on a DIV, make input radio:checked in that DIV'E - ReactJS?
It is necessary that when you click on the input block with the "radio" type, it would also be "checked", when you click again, the "checked" would be removed.
export default class Request extends Component {
constructor() {
super();
this.state = { }
this.handleClick = this.handleClick.bind(this);
}
this.handleClick() {
}
render() {
return (
<div class="block" onClick={ this.handleClick } role="button" tabIndex={ 0 }>
<input type="radio" name="radio" id="radio" />
</div>
);
}
}
Answer the question
In order to leave comments, you need to log in
export default class Request extends Component {
constructor() {
super();
this.state = {
checked: false
}
this.handleClick = this.handleClick.bind(this);
}
this.handleClick() {
this.setState({
checked: !this.state.checked
})
}
render() {
const {checked} = this.state
return (
<div class="block" onClick={ this.handleClick } role="button" tabIndex={ 0 }>
<input type="radio" name="radio" id="radio" checked={checked}/>
</div>
);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question