107
107
isOptionDeselectable(option) && index === typeAheadPointer,
108
108
'vs__dropdown-option--selected': isOptionSelected(option),
109
109
'vs__dropdown-option--highlight': index === typeAheadPointer,
110
+ 'vs__dropdown-option--kb-focus': hasKeyboardFocusBorder(index),
110
111
'vs__dropdown-option--disabled': !selectable(option),
111
112
}"
112
113
:aria-selected =" index === typeAheadPointer ? true : null"
113
- @mouseover = " selectable (option) ? (typeAheadPointer = index) : null "
114
+ @mousemove = " onMouseMove (option, index)"
114
115
@click.prevent.stop =" selectable(option) ? select(option) : null"
115
116
>
116
117
<slot name =" option" v-bind =" normalizeOptionForSlot(option)" >
@@ -660,6 +661,15 @@ export default {
660
661
},
661
662
},
662
663
664
+ /**
665
+ * Display a visible border around dropdown options
666
+ * which have keyboard focus.
667
+ */
668
+ keyboardFocusBorder: {
669
+ type: Boolean ,
670
+ default: false ,
671
+ },
672
+
663
673
/**
664
674
* A unique identifier used to generate IDs in HTML.
665
675
* Must be unique for every instance of the component.
@@ -675,6 +685,7 @@ export default {
675
685
search: ' ' ,
676
686
open: false ,
677
687
isComposing: false ,
688
+ isKeyboardNavigation: false ,
678
689
pushedTags: [],
679
690
// eslint-disable-next-line vue/no-reserved-keys
680
691
_value: [], // Internal value managed by Vue Select if no `value` prop is passed
@@ -1134,6 +1145,19 @@ export default {
1134
1145
return this .isOptionSelected (option) && this .deselectFromDropdown
1135
1146
},
1136
1147
1148
+ /**
1149
+ * Check if the option at the given index should display a
1150
+ * keyboard focus border.
1151
+ * @param {Number} index
1152
+ * @return {Boolean}
1153
+ */
1154
+ hasKeyboardFocusBorder (index ) {
1155
+ if (this .keyboardFocusBorder && this .isKeyboardNavigation ) {
1156
+ return index === this .typeAheadPointer
1157
+ }
1158
+ return false
1159
+ },
1160
+
1137
1161
/**
1138
1162
* Determine if two option objects are matching.
1139
1163
*
@@ -1309,6 +1333,20 @@ export default {
1309
1333
this .mousedown = false
1310
1334
},
1311
1335
1336
+ /**
1337
+ * Event-Handler for option mousemove
1338
+ * @param {Object|String} option
1339
+ * @param {Number} index
1340
+ * @return {void}
1341
+ */
1342
+ onMouseMove (option , index ) {
1343
+ this .isKeyboardNavigation = false
1344
+ if (! this .selectable (option)) {
1345
+ return
1346
+ }
1347
+ this .typeAheadPointer = index
1348
+ },
1349
+
1312
1350
/**
1313
1351
* Search <input> KeyBoardEvent handler.
1314
1352
* @param {KeyboardEvent} e
@@ -1330,6 +1368,7 @@ export default {
1330
1368
// up.prevent
1331
1369
38 : (e ) => {
1332
1370
e .preventDefault ()
1371
+ this .isKeyboardNavigation = true
1333
1372
if (! this .open ) {
1334
1373
this .open = true
1335
1374
return
@@ -1339,6 +1378,7 @@ export default {
1339
1378
// down.prevent
1340
1379
40 : (e ) => {
1341
1380
e .preventDefault ()
1381
+ this .isKeyboardNavigation = true
1342
1382
if (! this .open ) {
1343
1383
this .open = true
1344
1384
return
0 commit comments