Skip to content

Commit eb6d623

Browse files
committed
Autocomplete: Work around isContentEditable bug in Chrome
Fixes #14917 Closes gh-1673 (cherry picked from commit cbceca7)
1 parent 00e5e14 commit eb6d623

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

ui/autocomplete.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ $.widget( "ui.autocomplete", {
7171
// Inputs are always single-line, even if inside a contentEditable element
7272
// IE also treats inputs as contentEditable
7373
// All other element types are determined by whether or not they're contentEditable
74-
this.isMultiLine = isTextarea || !isInput && this.element.prop( "isContentEditable" );
74+
this.isMultiLine = isTextarea || !isInput && this._isContentEditable( this.element );
7575

7676
this.valueMethod = this.element[ isTextarea || isInput ? "val" : "text" ];
7777
this.isNewMenu = true;
@@ -585,6 +585,24 @@ $.widget( "ui.autocomplete", {
585585
// prevents moving cursor to beginning/end of the text field in some browsers
586586
event.preventDefault();
587587
}
588+
},
589+
590+
// Support: Chrome <=50
591+
// We should be able to just use this.element.prop( "isContentEditable" )
592+
// but hidden elements always report false in Chrome.
593+
// https://code.google.com/p/chromium/issues/detail?id=313082
594+
_isContentEditable: function( element ) {
595+
if ( !element.length ) {
596+
return false;
597+
}
598+
599+
var editable = element.prop( "contentEditable" );
600+
601+
if ( editable === "inherit" ) {
602+
return this._isContentEditable( element.parent() );
603+
}
604+
605+
return editable === "true";
588606
}
589607
});
590608

0 commit comments

Comments
 (0)