Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BootstrapDialog.moveFocus may be move focus to a none visible dialog! #224

Closed
hldgaofeng opened this issue Jan 13, 2016 · 5 comments
Closed
Labels

Comments

@hldgaofeng
Copy link

Open dialog_a -> dialog_b -> dialog_c , then press ESC will see the bug.

@nakupanda
Copy link
Owner

Please fork this jsfiddle http://jsfiddle.net/3c03mckb/1/ and create a live demo to reproduce the bug, thank you.

@hldgaofeng
Copy link
Author

try this code!

<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap3-dialog/1.34.9/css/bootstrap-dialog.css" rel="stylesheet" type="text/css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap3-dialog/1.34.9/js/bootstrap-dialog.js"></script>

<input type="button" value="btn1" id="mytestbtn1"/>
var dlg1 = new BootstrapDialog({
                        title: 'dialog1',
            message: 'press esc will can not close dialog1? because focus is in invisible dialog! try press tab key',
            autodestroy: false,
            buttons: [{
                    label: 'cancel',
                    action: function (dialog) {
                        return dialog.close();
                    }
                }]
        });
var dlg2 = new BootstrapDialog({
            title: 'dialog2',
            message: 'try press esc to find where is the focus?',
            autodestroy: false,
            buttons: [{
                    label: 'cancel',
                    action: function (dialog) {
                        return dialog.close();
                    }
                }]
        });
var dlg3 = new BootstrapDialog({
                        title: 'dialog3',
            message: 'press esc.',
            autodestroy: false,
            buttons: [{
                    label: 'cancel',
                    action: function (dialog) {
                        return dialog.close();
                    }
                }]
        });        

$('#mytestbtn1').click(function() {
  dlg1.open();
  dlg2.open();
  dlg3.open();
});

@hldgaofeng
Copy link
Author

This code can fix it?

    /**  
     * Move focus to next visible dialog.
     */
    BootstrapDialog.moveFocus = function () { 
        var lastDialogInstance = null;

        var topVisibleDialogZIndex = getTopVisibleDialogZIndex(); // @todo: try to implement.

        $.each(BootstrapDialog.dialogs, function (id, dialogInstance) {
            if( dialogInstance.opened && topVisibleDialogZIndex == dialogInstance.$modal.css('zIndex') ) {
                lastDialogInstance = dialogInstance;
            }    
        });  

        if (lastDialogInstance !== null && lastDialogInstance.isRealized()) {
            lastDialogInstance.getModal().focus();
        }    
    };  

@nakupanda nakupanda added the bug label Jan 13, 2016
@nakupanda
Copy link
Owner

Thank you, looking into it.

nakupanda added a commit that referenced this issue Jan 14, 2016
@nakupanda
Copy link
Owner

Patched, please see this commit. 185087c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants