Sho*_*mon 1 html javascript css modal-dialog reactjs
我正在使用react-responsive-modal来实现我的模式。我面临的一个问题是,当我单击屏幕上模态 div 之外的任意位置时,我的模态将关闭。我希望仅当我单击取消或关闭按钮时才关闭我的模式。我找到了 onOverlayClick 函数道具,并用它来应用 PreventDefault 但它没有用。
任何人都可以建议一种实现此功能的方法。提前致谢。
class CustomModal extends Component{
constructor(props) {
super(props);
}
onOverlay = (e) =>{
e.preventDefault();
}
render(){
const { props } = this;
return(
<Modal open={props.open} onClose={props.onCloseModal}
onOverlayClick={e =>this.onOverlay(e)} center>
<div className="on-setting-modal">
<h6>"are you sure ?"</h6>
<div className="on-setting-modal-buttons">
{
!!props.showCancel &&
<button onClick={props.onCloseModal} >Cancel</button>
}
<button onClick={props.onOkModal} >OK</button>
</div>
</div>
</Modal>
)
}
}
export default CustomModal
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3570 次 |
| 最近记录: |