首页 > 解决方案 > Chrome 更新(angularjs 和 bootstrap-ui)后,当光标在模态之外释放时,模态关闭

问题描述

有时,当我想快速选择输入的整个文本(在模态中)时,我会从文本的末尾开始选择并将鼠标向左移动,直到整个文本被选中,然后松开.

有时这个释放会发生在模态之外,因为鼠标移动很快。

描述运动的图片:

描述发布的图片

问题是当我在外面释放时模态是关闭的。

问题:如何防止模态在外部释放时关闭?

我可以通过点击外部关闭模式。但是发布活动不行。

我在用着:

更新: 我创建了一个 plunkr 和一个 GIF: https ://plnkr.co/edit/mxDLAdnrQ4p0KKyw?p=info

<div class="modal-body">
  <div class="form-group">
    <label for="">Foo</label>
    <input type="text" class="form-control input-sm" ng-model="foo">

    <p>Do this: select the text from right to left and release the mouse outside the modal.</p>
  </div>
</div>

动图:

模态在外面释放时关闭

更新 2

我有新信息!这在上次 Goole Chrome 更新后开始发生!我尝试使用另一台装有旧版 Chrome 的计算机,但模式没有关闭。

标签: angularjsgoogle-chromeangular-ui-bootstrap

解决方案


//prevent modal close when click starts in modal and ends on backdrop


$(document).on('mousedown', '.modal', function(e){      
    window.clickStartedInModal = $(e.target).is('.modal-dialog *');     
});

$(document).on('mouseup', '.modal', function(e){
    if(!$(e.target).is('.modal-dialog *') && window.clickStartedInModal) {
        window.preventModalClose = true;
    }           
});

$("#modal").on("hide.bs.modal", function (e) {
    if(window.preventModalClose){
        window.preventModalClose = false;
        return false;
    }     
}); 

推荐阅读