]> source.dussan.org Git - jquery-ui.git/commitdiff
Autocomplete: Restore focus after clicking a menu item, if necessary
authorScott González <scott.gonzalez@gmail.com>
Fri, 6 Mar 2015 21:30:17 +0000 (16:30 -0500)
committerScott González <scott.gonzalez@gmail.com>
Thu, 9 Jun 2016 16:17:16 +0000 (12:17 -0400)
Fixes #9201
Closes gh-1470

(cherry picked from commit 581bfb55bf4f4f614a6e0c0ac545cf1aa7d29d0a)

ui/autocomplete.js

index 6e477bb41aa1594663e301708571bbeef0c27e59..e4f998faa51fdec929817c8ec4cf1eb8d1749460 100644 (file)
@@ -221,6 +221,16 @@ $.widget( "ui.autocomplete", {
                                this.cancelBlur = true;
                                this._delay(function() {
                                        delete this.cancelBlur;
+
+                                       // Support: IE 8 only
+                                       // Right clicking a menu item or selecting text from the menu items will
+                                       // result in focus moving out of the input. However, we've already received
+                                       // and ignored the blur event because of the cancelBlur flag set above. So
+                                       // we restore focus to ensure that the menu closes properly based on the user's
+                                       // next actions.
+                                       if ( this.element[ 0 ] !== $.ui.safeActiveElement( this.document[ 0 ] ) ) {
+                                               this.element.focus();
+                                       }
                                });
 
                                // clicking on the scrollbar causes focus to shift to the body