1
我正在关注https://react.semantic-ui.com/modules/modal创建一个模态窗体。关闭模式在UI反应取消按钮
点击Cancel
按钮,我想关闭模态。我被限制不使用上面链接中建议的速记方法。我应该如何编写handleClose()函数来关闭Modal表单?
handleClose =() => {
console.log("close")
}
render(){
return(
<Modal trigger={<Button>Upload</Button>}closeIcon>
<Modal.Content>
<p>Please upload a valid file.</p>
<Form.Input
name="upload"
label=""
type="file"
onChange={e =>
this.setState({file_data : e.target.files[0]})}
>
</Form.Input>
</Modal.Content>
<Modal.Actions>
<Button onClick = {this.handleClose}>Cancel
</Button>
<Button positive onClick = {this.handleUpload}>Upload
</Button>
</Modal.Actions>
</Modal>
);
}
不错的解决方案Mervyn,你也可以在模式本身上使用onOpen回调,这样你就不必为按钮添加一个单击事件。如果您想在不同情况下重复使用模式并传递一个触发器(例如,从主键打开,从菜单项打开等),这很有用。 – Chris