Skip to content
This repository was archived by the owner on Nov 22, 2021. It is now read-only.

Commit e5afea6

Browse files
committed
Update to support comma and space on mobile keyboards
1 parent 87d0e6b commit e5afea6

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/tags-input.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@ export default function TagsInputDirective($timeout, $document, $window, $q, tag
314314

315315
scope.eventHandlers = {
316316
input: {
317+
textInput: function($event) {
318+
events.trigger('text-input', $event);
319+
},
317320
keydown($event) {
318321
events.trigger('input-keydown', $event);
319322
},
@@ -399,6 +402,24 @@ export default function TagsInputDirective($timeout, $document, $window, $q, tag
399402
element.triggerHandler('blur');
400403
setElementValidity();
401404
})
405+
.on('text-input', function(event) {
406+
// on mobile keydown doesn't provide keyCodes for space or comma (most keys really),
407+
// this will translate it so proper handling is triggered if those are pressed
408+
409+
let originalKey = event.originalEvent.data;
410+
let keyCode = null;
411+
412+
if (originalKey === " ") {
413+
keyCode = KEYS.space;
414+
} else if (originalKey === ",") {
415+
keyCode = KEYS.comma;
416+
}
417+
418+
if (keyCode) {
419+
event.keyCode = keyCode;
420+
events.trigger('input-keydown', event);
421+
}
422+
})
402423
.on('input-keydown', event => {
403424
let key = event.keyCode;
404425

templates/tags-input.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
ng-model="newTag.text"
1414
ng-model-options="{getterSetter: true}"
1515
ng-keydown="eventHandlers.input.keydown($event)"
16+
ng-on-text_input="eventHandlers.input.textInput($event)"
1617
ng-focus="eventHandlers.input.focus($event)"
1718
ng-blur="eventHandlers.input.blur($event)"
1819
ng-paste="eventHandlers.input.paste($event)"
@@ -22,4 +23,4 @@
2223
ti-bind-attrs="{type: options.type, placeholder: options.placeholder, tabindex: options.tabindex, spellcheck: options.spellcheck}"
2324
ti-autosize>
2425
</div>
25-
</div>
26+
</div>

0 commit comments

Comments
 (0)