Skip to content

Autocomplete: Work around isContentEditable bug in Chrome #1673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion ui/widgets/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,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;
Expand Down Expand Up @@ -614,6 +614,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";
}
} );

Expand Down