Remove use of keyboardevent.which as its deprecated in autocomplete

This commit is contained in:
Andrew Bastin
2020-08-28 23:58:38 -04:00
parent 993a8f83ff
commit 31cefd7dd0

View File

@@ -76,12 +76,6 @@
</style> </style>
<script> <script>
const KEY_TAB = 9
const KEY_ESC = 27
const KEY_ARROW_UP = 38
const KEY_ARROW_DOWN = 40
export default { export default {
props: { props: {
spellcheck: { spellcheck: {
@@ -127,7 +121,7 @@ export default {
methods: { methods: {
updateSuggestions(event) { updateSuggestions(event) {
// Hide suggestions if ESC pressed. // Hide suggestions if ESC pressed.
if (event.which && event.which === KEY_ESC) { if (event.code && event.code === "Escape") {
event.preventDefault() event.preventDefault()
this.suggestionsVisible = false this.suggestionsVisible = false
this.currentSuggestionIndex = -1 this.currentSuggestionIndex = -1
@@ -151,14 +145,14 @@ export default {
}, },
handleKeystroke(event) { handleKeystroke(event) {
switch (event.which) { switch (event.code) {
case KEY_ARROW_UP: case "ArrowUp":
event.preventDefault() event.preventDefault()
this.currentSuggestionIndex = this.currentSuggestionIndex =
this.currentSuggestionIndex - 1 >= 0 ? this.currentSuggestionIndex - 1 : 0 this.currentSuggestionIndex - 1 >= 0 ? this.currentSuggestionIndex - 1 : 0
break break
case KEY_ARROW_DOWN: case "ArrowDown":
event.preventDefault() event.preventDefault()
this.currentSuggestionIndex = this.currentSuggestionIndex =
this.currentSuggestionIndex < this.suggestions.length - 1 this.currentSuggestionIndex < this.suggestions.length - 1
@@ -166,18 +160,13 @@ export default {
: this.suggestions.length - 1 : this.suggestions.length - 1
break break
case KEY_TAB: case "Tab":
event.preventDefault() event.preventDefault()
let activeSuggestion = this.suggestions[ let activeSuggestion = this.suggestions[
this.currentSuggestionIndex >= 0 ? this.currentSuggestionIndex : 0 this.currentSuggestionIndex >= 0 ? this.currentSuggestionIndex : 0
] ]
if (activeSuggestion) {
let input = this.text.substring(0, this.selectionStart) let input = this.text.substring(0, this.selectionStart)
this.text = input + activeSuggestion this.text = input + activeSuggestion
}
break
default:
break break
} }
}, },