Add Keys enum; use it when detecting keystrokes in the input suggestions component.

This commit is contained in:
Paulo Reis 2018-06-27 12:21:26 +01:00
parent bebbc433bf
commit 522084a504
3 changed files with 19 additions and 2 deletions

View file

@ -1,7 +1,7 @@
define [
"base"
], (App) ->
inputSuggestionsController = ($scope, $element, $attrs) ->
inputSuggestionsController = ($scope, $element, $attrs, Keys) ->
ctrl = @
ctrl.showHint = false
ctrl.hasFocus = false
@ -14,7 +14,7 @@ define [
ctrl.suggestion = null
ctrl.onBlur()
ctrl.handleKeyDown = ($event) ->
if ($event.which == 9 or $event.which == 13) and ctrl.suggestion? and ctrl.suggestion != ""
if ($event.which == Keys.TAB or $event.which == Keys.ENTER) and ctrl.suggestion? and ctrl.suggestion != ""
$event.preventDefault()
ctrl.localNgModel += ctrl.suggestion
ctrl.suggestion = null

View file

@ -22,6 +22,7 @@ define [
"main/learn"
"main/affiliations/controllers/UserAffiliationsController"
"main/affiliations/factories/UserAffiliationsDataService"
"main/keys"
"analytics/AbTestingManager"
"directives/asyncForm"
"directives/stopPropagation"

View file

@ -0,0 +1,16 @@
define [
"base"
], (App) ->
App.constant "Keys",
ENTER : 13
TAB : 9
ESCAPE : 27
SPACE : 32
BACKSPACE : 8
UP : 38
DOWN : 40
LEFT : 37
RIGHT : 39
PERIOD : 190
COMMA : 188
END : 35