]> source.dussan.org Git - jquery-ui.git/commitdiff
Menu: Don't reset active element until after triggering `blur` event
authorScott González <scott.gonzalez@gmail.com>
Tue, 12 Apr 2016 19:10:22 +0000 (15:10 -0400)
committerScott González <scott.gonzalez@gmail.com>
Wed, 13 Apr 2016 15:08:21 +0000 (11:08 -0400)
This ensures that `ui.item` actually exists in the `blur` event.

Fixes #14945
Closes gh-1696

tests/unit/menu/events.js
ui/widgets/menu.js

index 1500c3478b0b517eea74284e55a8bc35f3bca248..4d2af394f89927f9fc0bb21191147aaa2fdbe610 100644 (file)
@@ -48,20 +48,22 @@ test( "handle click on custom item menu", function() {
 } );
 
 asyncTest( "handle blur", function() {
-       expect( 1 );
+       expect( 2 );
        var blurHandled = false,
+               index = 1,
                element = $( "#menu1" ).menu( {
-                       blur: function( event ) {
+                       blur: function( event, ui ) {
 
                                // Ignore duplicate blur event fired by IE
                                if ( !blurHandled ) {
                                        blurHandled = true;
                                        equal( event.type, "menublur", "blur event.type is 'menublur'" );
+                                       strictEqual( ui.item[ 0 ], element.children()[ index ], "ui.item" );
                                }
                        }
                } );
 
-       click( element, "1" );
+       click( element, index );
        setTimeout( function() {
                element.trigger( "blur" );
                setTimeout( function() {
@@ -71,20 +73,22 @@ asyncTest( "handle blur", function() {
 } );
 
 asyncTest( "handle blur via click outside", function() {
-       expect( 1 );
+       expect( 2 );
        var blurHandled = false,
+               index = 1,
                element = $( "#menu1" ).menu( {
-                       blur: function( event ) {
+                       blur: function( event, ui ) {
 
                                // Ignore duplicate blur event fired by IE
                                if ( !blurHandled ) {
                                        blurHandled = true;
                                        equal( event.type, "menublur", "blur event.type is 'menublur'" );
+                                       strictEqual( ui.item[ 0 ], element.children()[ index ], "ui.item" );
                                }
                        }
                } );
 
-       click( element, "1" );
+       click( element, index );
        setTimeout( function() {
                $( "<a>", { id: "remove" } ).appendTo( "body" ).trigger( "click" );
                setTimeout( function() {
index f63105fa771004e984b48a3e4e47b8fbfa0bffa7..22db41988ec8a28cf0f4c4cf4abad875799ab665 100644 (file)
@@ -434,9 +434,9 @@ return $.widget( "ui.menu", {
 
                this._removeClass( this.active.children( ".ui-menu-item-wrapper" ),
                        null, "ui-state-active" );
-               this.active = null;
 
                this._trigger( "blur", event, { item: this.active } );
+               this.active = null;
        },
 
        _startOpening: function( submenu ) {