mirror of
https://github.com/jquery/jquery-ui.git
synced 2025-01-07 20:34:24 +00:00
Dialog: Focus tabbable only when dialog lost focus before.
This commit is contained in:
parent
6edce86733
commit
0848040d3e
@ -39,6 +39,51 @@ test("open", function() {
|
||||
el.remove();
|
||||
});
|
||||
|
||||
|
||||
test( "focus", function() {
|
||||
expect( 5 );
|
||||
var el, other;
|
||||
el = $("#dialog1").dialog({
|
||||
autoOpen: false
|
||||
});
|
||||
other = $("#dialog2").dialog({
|
||||
autoOpen: false
|
||||
});
|
||||
|
||||
el.one( "dialogopen", function() {
|
||||
ok( true, "open, just once" );
|
||||
});
|
||||
el.one( "dialogfocus", function() {
|
||||
ok( true, "focus on open" );
|
||||
});
|
||||
other.dialog( "open" );
|
||||
|
||||
el.one( "dialogfocus", function() {
|
||||
ok( true, "when opening and already open and wasn't on top" );
|
||||
});
|
||||
other.dialog( "open" );
|
||||
el.dialog( "open" );
|
||||
|
||||
el.one( "dialogfocus", function() {
|
||||
ok( true, "when calling moveToTop and wasn't on top" );
|
||||
});
|
||||
other.dialog( "moveToTop" );
|
||||
el.dialog( "moveToTop" );
|
||||
|
||||
el.bind( "dialogfocus", function() {
|
||||
ok( true, "when mousedown anywhere on the dialog and it wasn't on top" );
|
||||
});
|
||||
other.dialog( "moveToTop" );
|
||||
el.trigger( "mousedown" );
|
||||
|
||||
// triggers just once when already on top
|
||||
el.dialog( "open" );
|
||||
el.dialog( "moveToTop" );
|
||||
el.trigger( "mousedown" );
|
||||
|
||||
el.add( other ).remove();
|
||||
});
|
||||
|
||||
test("dragStart", function() {
|
||||
expect(9);
|
||||
|
||||
|
23
ui/jquery.ui.dialog.js
vendored
23
ui/jquery.ui.dialog.js
vendored
@ -117,7 +117,9 @@ $.widget("ui.dialog", {
|
||||
}
|
||||
})
|
||||
.mousedown(function( event ) {
|
||||
that.moveToTop( event );
|
||||
if ( that._moveToTop( event ) ) {
|
||||
that._focusTabbable();
|
||||
}
|
||||
})
|
||||
.appendTo( this.document[ 0 ].body );
|
||||
|
||||
@ -292,18 +294,23 @@ $.widget("ui.dialog", {
|
||||
return this._isOpen;
|
||||
},
|
||||
|
||||
moveToTop: function( event, silent ) {
|
||||
var moved = this.uiDialog.nextAll( ":visible" ).insertBefore( this.uiDialog );
|
||||
if ( !silent && moved.length ) {
|
||||
moveToTop: function() {
|
||||
this._moveToTop();
|
||||
},
|
||||
|
||||
_moveToTop: function( event, silent ) {
|
||||
var moved = !!this.uiDialog.nextAll( ":visible" ).insertBefore( this.uiDialog ).length;
|
||||
if ( !silent && moved ) {
|
||||
this._trigger( "focus", event );
|
||||
}
|
||||
return moved;
|
||||
},
|
||||
|
||||
open: function() {
|
||||
if ( this._isOpen ) {
|
||||
this.moveToTop( null );
|
||||
// TODO run this only when dialog wasn't focused?
|
||||
this._focusTabbable();
|
||||
if ( this._moveToTop() ) {
|
||||
this._focusTabbable();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -316,7 +323,7 @@ $.widget("ui.dialog", {
|
||||
this._size();
|
||||
this._position( options.position );
|
||||
this.overlay = options.modal ? new $.ui.dialog.overlay( this ) : null;
|
||||
this.moveToTop( null, true );
|
||||
this._moveToTop( null, true );
|
||||
this._show( uiDialog, options.show );
|
||||
|
||||
this._focusTabbable();
|
||||
|
Loading…
Reference in New Issue
Block a user