L
L
litash2017-07-20 10:41:40
css
litash, 2017-07-20 10:41:40

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

1 answer(s)
L
Leo Developer, 2017-07-20
@litash

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 question

Ask a Question

731 491 924 answers to any question