2
0
mirror of https://github.com/tenrok/vue-select.git synced 2026-06-16 09:10:33 +03:00

fix: Keep focus on input after select to improve accessibility (#1727)

Co-authored-by: Jeff Sagal <sagalbot@gmail.com>

Huge thanks to @Pytal for the great work!
This commit is contained in:
Pytal
2022-12-16 12:47:19 -08:00
committed by GitHub
parent 8d2ac2d36c
commit 26f082713e
6 changed files with 74 additions and 7 deletions
+22 -4
View File
@@ -571,7 +571,12 @@ export default {
*/
selectOnKeyCodes: {
type: Array,
default: () => [13],
default: () => [
// enter
13,
// space
32,
],
},
/**
@@ -953,6 +958,12 @@ export default {
open(isOpen) {
this.$emit(isOpen ? 'open' : 'close')
},
search(search) {
if (search.length) {
this.open = true
}
},
},
created() {
@@ -1035,7 +1046,6 @@ export default {
onAfterSelect(option) {
if (this.closeOnSelect) {
this.open = !this.open
this.searchEl.blur()
}
if (this.clearSearchOnSelect) {
@@ -1240,7 +1250,7 @@ export default {
*/
onEscape() {
if (!this.search.length) {
this.searchEl.blur()
this.open = false
} else {
this.search = ''
}
@@ -1302,7 +1312,7 @@ export default {
/**
* Search <input> KeyBoardEvent handler.
* @param e {KeyboardEvent}
* @param {KeyboardEvent} e
* @return {Function}
*/
onSearchKeyDown(e) {
@@ -1321,11 +1331,19 @@ export default {
// up.prevent
38: (e) => {
e.preventDefault()
if (!this.open) {
this.open = true
return
}
return this.typeAheadUp()
},
// down.prevent
40: (e) => {
e.preventDefault()
if (!this.open) {
this.open = true
return
}
return this.typeAheadDown()
},
}
+5 -1
View File
@@ -76,12 +76,16 @@ export default {
* Moves the pointer to the last selected option.
*/
typeAheadToLastSelected() {
this.typeAheadPointer =
const indexOfLastSelected =
this.selectedValue.length !== 0
? this.filteredOptions.indexOf(
this.selectedValue[this.selectedValue.length - 1]
)
: -1
if (indexOfLastSelected !== -1) {
this.typeAheadPointer = indexOfLastSelected
}
},
},
}