Skip to content

Commit

Permalink
fix(typeahead): Fix crash with contenteditable inputs
Browse files Browse the repository at this point in the history
Currently the Typeahead module works well with `<input>`s, but throws an
error for HTML5 `contenteditable` inputs [1].

This patch fixes this by using the `innerText` property (the one used
for contenteditable inputs) when `value` is not available.

[1]: http://www.w3schools.com/tags/att_global_contenteditable.asp
  • Loading branch information
adrienverge authored and valorkin committed Oct 3, 2016
1 parent 2bf9fd8 commit 47b9fb1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion components/typeahead/typeahead.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ export class TypeaheadDirective implements OnInit {
}
}

if (e.target.value.trim().length >= this.typeaheadMinLength) {
// For `<input>`s, use the `value` property. For others that don't have a
// `value` (such as `<span contenteditable="true">`, use `innerText`.
const value = e.target.value !== undefined ? e.target.value : e.target.innerText;
if (value.trim().length >= this.typeaheadMinLength) {
this.typeaheadLoading.emit(true);
this.keyUpEventEmitter.emit(e.target.value);
} else {
Expand Down

0 comments on commit 47b9fb1

Please sign in to comment.