I have a Modal where the user needs to fill in some forms and save whatever was filled in through a button in the Modal. When the user saves I would like the modal to close. I can get this done, through using the open
prop on the Modal
component. But if I do this, the modal doesn't close when I attempt to do so through the closeIcon.
What can I do to allow the user to close the Modal through both methods?
Here is my current modal code:
handleCreateButton (evt) {
evt.preventDefault()
// ...
// code to save whatever was typed in the form
// ...
this.setState({showModal: false})
}
renderModalForm () {
const {
something,
showModal
} = this.state
// if I have the open props, I get to close the Modal after the button is clicked
// however, when using the icon or clicking on dimmer it wont work anymore.
return (
<Modal closeIcon closeOnDimmerClick open={showModal} trigger={<Button onClick={() => this.setState({showModal: true})}><Icon className='plus'/>New Challenge</Button>}>
<Modal.Header>My Modal</Modal.Header>
<Modal.Content>
<Form>
<Form.Input
label='Something'
value={something}
onChange={(evt) => this.handleChangeForms('something', evt.target.value)}
/>
<Button onClick={(evt) => this.handleCreateButton(evt)}>Save</Button>
</Form>
</Modal.Content>
</Modal>
)
}