Reputation: 49
I am using react-modal but my button to close the modal is not firing the onClick={this.handleCloseModal} making the button inside the modal completely unresponsive. I have been trying different things for hours and cannot figure out why this is not working. No errors pop up in console and I cannot console log anything.... Please see code below, I have just been beating my head against a wall with no answers. I am fairly new to react but feel like this should be working as there are no errors. Thank you in advance!
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>
)
}
}
Upvotes: 1
Views: 8450
Reputation: 2108
Try removing the modal outside of the li tag? I'm just taking a wild guess here, perhaps it's triggering onClick={this.handleOpenModal} wherever you click on the Modal since it's child of the list item?? Worth a try :)
Upvotes: 3