jQuery UI Focus Stealing

后端 未结 5 1366
遇见更好的自我
遇见更好的自我 2020-12-17 18:16

Whenever I type something in the following Insert Hyperlink text input, all the words are going to textarea behind it. OK and Cancel buttons are working fine bu

5条回答
  •  庸人自扰
    2020-12-17 19:00

    thats because jquery prevents focus outside of dialog child, jquery has this method you can read, that will whitelist which other elements you want to allow focus.

    "_allowInteraction( event )Returns: Boolean Modal dialogs do not allow users to interact with elements behind the dialog. This can be problematic for elements that are not children of the dialog, but are absolutely positioned to appear as though they are. The _allowInteraction() method determines whether the user should be allowed to interact with a given target element; therefore, it can be used to whitelist elements that are not children of the dialog but you want users to be able to use."

    https://api.jqueryui.com/dialog/#method-_allowInteraction

    So what i do to disable this "block focus" to some items with class .other-popups is add this line in the code

    $.widget( "ui.dialog", $.ui.dialog, {
        _allowInteraction: function( event ) {
            return !!$( event.target ).closest( ".other-popups" ).length || this._super( event );
        }
    });
    

    Or to disable completly

     $.widget( "ui.dialog", $.ui.dialog, {
            _allowInteraction: function( event ) {
                return true ;
            }
        });
    

提交回复
热议问题