[英]React-Modal Close button not working
我正在使用react-modal,但是我关闭模式的按钮没有触发onClick = {this.handleCloseModal},使得模式内部的按钮完全没有响应。 数小时以来,我一直在尝试不同的方法,无法弄清为什么它不起作用。 控制台中不会弹出任何错误,并且我也无法控制台记录任何内容。...请参阅下面的代码,我只是在头顶上打着头,没有任何答案。 我现在还很陌生,但是由于没有错误,因此应该可以正常工作。 先感谢您!
class Project extends React.Component {
constructor () {
super();
this.state = {
showModal: false
};
this.handleOpenModal = this.handleOpenModal.bind(this);
this.handleCloseModal = this.handleCloseModal.bind(this);
}
handleOpenModal () {
this.setState({ showModal: true });
}
handleCloseModal () {
this.setState({ showModal: false });
}
componentWillMount() {
ReactModal.setAppElement('body');
}
render() {
const details = this.props.details;
return (
<li className="Project" onClick={this.handleOpenModal}>
<img className="Project-image" src={'projects/' + details.image} alt={details.name}/>
<div className="Project-overlay">
<p>{details.name}</p>
</div>
<div >
<ReactModal
isOpen={this.state.showModal}
contentLabel="This is my Mods"
shouldCloseOnOverlayClick={true}
onRequestClose={this.handleCloseModal}
>
<div className="modal-header">
<h3>{details.name}</h3>
</div>
<div className="modal-body">
</div>
<div className="modal-footer">
<button onClick={this.handleCloseModal}>Close Modal</button>
</div>
</ReactModal>
</div>
<div className="Project-tag">
<p>{details.tag}</p>
</div>
</li>
)
}
}
尝试删除li标签之外的模式吗? 我在这里只是一个大胆的猜测,也许它会触发onClick = {this.handleOpenModal},无论您在何处单击Modal,因为它是列表项的子项? 值得一试 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.