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

Commit

Permalink
Update to support comma and space on mobile keyboards
Browse files Browse the repository at this point in the history
  • Loading branch information
phazei committed Dec 2, 2019
1 parent 87d0e6b commit e5afea6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/tags-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ export default function TagsInputDirective($timeout, $document, $window, $q, tag

scope.eventHandlers = {
input: {
textInput: function($event) {
events.trigger('text-input', $event);
},
keydown($event) {
events.trigger('input-keydown', $event);
},
Expand Down Expand Up @@ -399,6 +402,24 @@ export default function TagsInputDirective($timeout, $document, $window, $q, tag
element.triggerHandler('blur');
setElementValidity();
})
.on('text-input', function(event) {
// on mobile keydown doesn't provide keyCodes for space or comma (most keys really),
// this will translate it so proper handling is triggered if those are pressed

let originalKey = event.originalEvent.data;
let keyCode = null;

if (originalKey === " ") {
keyCode = KEYS.space;
} else if (originalKey === ",") {
keyCode = KEYS.comma;
}

if (keyCode) {
event.keyCode = keyCode;
events.trigger('input-keydown', event);
}
})
.on('input-keydown', event => {
let key = event.keyCode;

Expand Down
3 changes: 2 additions & 1 deletion templates/tags-input.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
ng-model="newTag.text"
ng-model-options="{getterSetter: true}"
ng-keydown="eventHandlers.input.keydown($event)"
ng-on-text_input="eventHandlers.input.textInput($event)"
ng-focus="eventHandlers.input.focus($event)"
ng-blur="eventHandlers.input.blur($event)"
ng-paste="eventHandlers.input.paste($event)"
Expand All @@ -22,4 +23,4 @@
ti-bind-attrs="{type: options.type, placeholder: options.placeholder, tabindex: options.tabindex, spellcheck: options.spellcheck}"
ti-autosize>
</div>
</div>
</div>

0 comments on commit e5afea6

Please sign in to comment.