From 47b9fb117a0ef27669c23c64501029bccef2b424 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Verg=C3=A9?= Date: Fri, 30 Sep 2016 16:42:32 +0200 Subject: [PATCH] fix(typeahead): Fix crash with `contenteditable` inputs Currently the Typeahead module works well with ``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 --- components/typeahead/typeahead.directive.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/components/typeahead/typeahead.directive.ts b/components/typeahead/typeahead.directive.ts index d3e3428a1b..a21c724c50 100644 --- a/components/typeahead/typeahead.directive.ts +++ b/components/typeahead/typeahead.directive.ts @@ -92,7 +92,10 @@ export class TypeaheadDirective implements OnInit { } } - if (e.target.value.trim().length >= this.typeaheadMinLength) { + // For ``s, use the `value` property. For others that don't have a + // `value` (such as ``, 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 {