停止模式以关闭外部点击

时间:2018-05-15 15:40:11

标签: reactjs react-bootstrap

点击容器外部时,是否可以执行任何操作以使Modal保持打开状态?

我有一个密码更改屏幕,点击Modal按钮时我需要submit仅关闭。只有在满足某些条件时才会激活。

<div>
            <Modal show={this.state.show} onHide={this.handleClose}>
                <Modal.Header>
                    <Modal.Title>Change Password</Modal.Title>
                </Modal.Header>
                <Modal.Body>
                    <form className="form-horizontal" style={{margin:0}}>
                        <div className='password-heading'>This is the first time you have logged in.</div>
                        <div className='password-heading'>Please set a new password for your account.</div>
                        <br/>

                        <label className="password">Password
                            <input type={this.state.type} className="password__input" onChange={this.passwordStrength}/>
                            <span className="password__show" onClick={this.showHide}>{this.state.type === 'input' ? 'Hide' : 'Show'}</span>
                            <span className="password__strength" data-score={this.state.score} ><div className="strength_string">{this.state.strength}</div></span>
                        </label>
                        <br/>
                        <label className="password">Confirm Password
                            <input type={this.state.type} className="password__input" onChange={this.passwordStrength}/>
                        </label>

                    </form>
                    <br/>
                </Modal.Body>
                <Modal.Footer>
                    <Button onClick={this.submitPassword} disabled={this.state.isDisabled}>Submit</Button>
                </Modal.Footer>
            </Modal>
        </div>

2 个答案:

答案 0 :(得分:7)

将模态的背景设置为静态。模态组件的支柱为backdrop,设置为backdrop="static"

<div>
    <Modal show={this.state.show} onHide={this.handleClose} backdrop="static">
        <Modal.Header>
            <Modal.Title>Change Password</Modal.Title>
        </Modal.Header>
        <Modal.Body>
            <form className="form-horizontal" style={{margin:0}}>
                <div className='password-heading'>This is the first time you have logged in.</div>
                <div className='password-heading'>Please set a new password for your account.</div>
                <br/>

                <label className="password">Password
                    <input type={this.state.type} className="password__input" onChange={this.passwordStrength}/>
                    <span className="password__show" onClick={this.showHide}>{this.state.type === 'input' ? 'Hide' : 'Show'}</span>
                    <span className="password__strength" data-score={this.state.score}>
                        <div className="strength_string">{this.state.strength}</div>
                    </span>
                </label>
                <br/>
                <label className="password">Confirm Password
                    <input type={this.state.type} className="password__input" onChange={this.passwordStrength}/>
                </label>

            </form>
            <br/>
        </Modal.Body>
        <Modal.Footer>
            <Button onClick={this.submitPassword} disabled={this.state.isDisabled}>Submit</Button>
        </Modal.Footer>
    </Modal>
</div>

来自文档:

  

为单击时未触发“onHide”的背景指定“静态”。   react-bootstrap

答案 1 :(得分:0)

从模态中删除 onHide onHide={this.handleClose}