]> source.dussan.org Git - jquery-ui.git/commitdiff
Autocomplete: Work around `isContentEditable` bug in Chrome
authorScott González <scott.gonzalez@gmail.com>
Tue, 16 Feb 2016 15:22:45 +0000 (10:22 -0500)
committerScott González <scott.gonzalez@gmail.com>
Thu, 9 Jun 2016 21:38:46 +0000 (17:38 -0400)
Fixes #14917
Closes gh-1673

(cherry picked from commit cbceca7091b17e05c5a9ba887ef54761568bb70b)

ui/autocomplete.js

index 0741dadb14276370e0f82f3b0eea1c7839a90e43..fe14726bec0c46b88c5aae56edd7ad01e0398f05 100644 (file)
@@ -71,7 +71,7 @@ $.widget( "ui.autocomplete", {
                // Inputs are always single-line, even if inside a contentEditable element
                // IE also treats inputs as contentEditable
                // All other element types are determined by whether or not they're contentEditable
-               this.isMultiLine = isTextarea || !isInput && this.element.prop( "isContentEditable" );
+               this.isMultiLine = isTextarea || !isInput && this._isContentEditable( this.element );
 
                this.valueMethod = this.element[ isTextarea || isInput ? "val" : "text" ];
                this.isNewMenu = true;
@@ -585,6 +585,24 @@ $.widget( "ui.autocomplete", {
                        // prevents moving cursor to beginning/end of the text field in some browsers
                        event.preventDefault();
                }
+       },
+
+       // Support: Chrome <=50
+       // We should be able to just use this.element.prop( "isContentEditable" )
+       // but hidden elements always report false in Chrome.
+       // https://code.google.com/p/chromium/issues/detail?id=313082
+       _isContentEditable: function( element ) {
+               if ( !element.length ) {
+                       return false;
+               }
+
+               var editable = element.prop( "contentEditable" );
+
+               if ( editable === "inherit" ) {
+                 return this._isContentEditable( element.parent() );
+               }
+
+               return editable === "true";
        }
 });