Skip to content

Commit

Permalink
Draggable: active element blurs when clicking on a draggable. Fixes #…
Browse files Browse the repository at this point in the history
…4261 - Draggable: Inputs do not blur when clicking on a draggable
  • Loading branch information
Steven Luscher authored and mikesherov committed Jun 19, 2013
1 parent bca3e05 commit fcd1caf
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
12 changes: 1 addition & 11 deletions tests/unit/datepicker/datepicker_test_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@ TestHelpers.datepicker = {
var id = $( "<input>" ).appendTo( "#qunit-fixture" );
return TestHelpers.datepicker.init( id, options );
},
onFocus: function( element, onFocus ) {
var fn = function( event ){
if( !event.originalEvent ) {
return;
}
element.unbind( "focus", fn );
onFocus();
};

element.bind( "focus", fn )[ 0 ].focus();
},
onFocus: TestHelpers.onFocus,
PROP_NAME: "datepicker"
};
16 changes: 16 additions & 0 deletions tests/unit/draggable/draggable_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,20 @@ test( "#8399: A draggable should become the active element after you are finishe
strictEqual( document.activeElement, element.get( 0 ), "finishing moving a draggable anchor made it the active element" );
});

asyncTest( "#4261: active element should blur when mousing down on a draggable", function() {
expect( 2 );

var textInput = $( "<input>" ).appendTo( "#qunit-fixture" ),
element = $( "#draggable1" ).draggable();

TestHelpers.onFocus( textInput, function() {
strictEqual( document.activeElement, textInput.get( 0 ), "ensure that a focussed text input is the active element before mousing down on a draggable" );

TestHelpers.draggable.move( element, 50, 50 );

notStrictEqual( document.activeElement, textInput.get( 0 ), "ensure the text input is no longer the active element after mousing down on a draggable" );
start();
});
});

})( jQuery );
12 changes: 12 additions & 0 deletions tests/unit/testsuite.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,18 @@ TestHelpers.commonWidgetTests = function( widget, settings ) {
});
};

TestHelpers.onFocus= function( element, onFocus ) {
var fn = function( event ){
if( !event.originalEvent ) {
return;
}
element.unbind( "focus", fn );
onFocus();
};

element.bind( "focus", fn )[ 0 ].focus();
};

/*
* Taken from https://github.com/jquery/qunit/tree/master/addons/close-enough
*/
Expand Down
2 changes: 2 additions & 0 deletions ui/jquery.ui.draggable.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ $.widget("ui.draggable", $.ui.mouse, {

var o = this.options;

$( document.activeElement ).blur();

// among others, prevent a drag on a resizable-handle
if (this.helper || o.disabled || $(event.target).closest(".ui-resizable-handle").length > 0) {
return false;
Expand Down

6 comments on commit fcd1caf

@johnnyshields
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@steveluscher @mikesherov the change to jquery.ui.draggable.js caused this regression issue: http://bugs.jqueryui.com/ticket/9520

@steveluscher
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're kidding? Blurring the active element causes the browser window to change stacking order on IE9? I can hardly believe it, but then again…

@johnnyshields
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite a cynical interpretation of the JS spec by Microsoft. Why would anyone need the browser window to "blur" with respect to other OS windows??

@tjvantoll
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're kidding? Blurring the active element causes the browser window to change stacking order on IE9? I can hardly believe it, but then again…

@steveluscher Only if document.activeElement is the <body>, but yeah, insanity. It happens in IE10 as well.

@steveluscher
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@guidobouman
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A simple check if the active element is within the draggable scope would do?

Please sign in to comment.