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

Update to support comma and space on mobile keyboards #885

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
23 changes: 23 additions & 0 deletions src/tags-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ export default function TagsInputDirective($timeout, $document, $window, $q, tag
self.clearSelection();
events.trigger('tag-removed', { $tag: tag });
return tag;
}).catch(() => {
//can't remove tag
});
};

Expand Down Expand Up @@ -314,6 +316,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 +404,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 = tiConstants.KEYS.space;
} else if (originalKey === ",") {
keyCode = tiConstants.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>
Loading