Skip to content

Commit fcd1caf

Browse files
Steven Luschermikesherov
Steven Luscher
authored andcommitted
Draggable: active element blurs when clicking on a draggable. Fixes #4261 - Draggable: Inputs do not blur when clicking on a draggable
1 parent bca3e05 commit fcd1caf

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

tests/unit/datepicker/datepicker_test_helpers.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,6 @@ TestHelpers.datepicker = {
2222
var id = $( "<input>" ).appendTo( "#qunit-fixture" );
2323
return TestHelpers.datepicker.init( id, options );
2424
},
25-
onFocus: function( element, onFocus ) {
26-
var fn = function( event ){
27-
if( !event.originalEvent ) {
28-
return;
29-
}
30-
element.unbind( "focus", fn );
31-
onFocus();
32-
};
33-
34-
element.bind( "focus", fn )[ 0 ].focus();
35-
},
25+
onFocus: TestHelpers.onFocus,
3626
PROP_NAME: "datepicker"
3727
};

tests/unit/draggable/draggable_core.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,20 @@ test( "#8399: A draggable should become the active element after you are finishe
199199
strictEqual( document.activeElement, element.get( 0 ), "finishing moving a draggable anchor made it the active element" );
200200
});
201201

202+
asyncTest( "#4261: active element should blur when mousing down on a draggable", function() {
203+
expect( 2 );
204+
205+
var textInput = $( "<input>" ).appendTo( "#qunit-fixture" ),
206+
element = $( "#draggable1" ).draggable();
207+
208+
TestHelpers.onFocus( textInput, function() {
209+
strictEqual( document.activeElement, textInput.get( 0 ), "ensure that a focussed text input is the active element before mousing down on a draggable" );
210+
211+
TestHelpers.draggable.move( element, 50, 50 );
212+
213+
notStrictEqual( document.activeElement, textInput.get( 0 ), "ensure the text input is no longer the active element after mousing down on a draggable" );
214+
start();
215+
});
216+
});
217+
202218
})( jQuery );

tests/unit/testsuite.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,18 @@ TestHelpers.commonWidgetTests = function( widget, settings ) {
175175
});
176176
};
177177

178+
TestHelpers.onFocus= function( element, onFocus ) {
179+
var fn = function( event ){
180+
if( !event.originalEvent ) {
181+
return;
182+
}
183+
element.unbind( "focus", fn );
184+
onFocus();
185+
};
186+
187+
element.bind( "focus", fn )[ 0 ].focus();
188+
};
189+
178190
/*
179191
* Taken from https://github.com/jquery/qunit/tree/master/addons/close-enough
180192
*/

ui/jquery.ui.draggable.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ $.widget("ui.draggable", $.ui.mouse, {
7878

7979
var o = this.options;
8080

81+
$( document.activeElement ).blur();
82+
8183
// among others, prevent a drag on a resizable-handle
8284
if (this.helper || o.disabled || $(event.target).closest(".ui-resizable-handle").length > 0) {
8385
return false;

0 commit comments

Comments
 (0)