@@ -20,6 +20,8 @@ export default function useKeyboard (props, context, dep)
20
20
const selectPointer = dep . selectPointer
21
21
const backwardPointer = dep . backwardPointer
22
22
const forwardPointer = dep . forwardPointer
23
+ const multiselect = dep . multiselect
24
+ const tags = dep . tags
23
25
const isOpen = dep . isOpen
24
26
const open = dep . open
25
27
const blur = dep . blur
@@ -61,6 +63,14 @@ export default function useKeyboard (props, context, dep)
61
63
const handleKeydown = ( e ) => {
62
64
context . emit ( 'keydown' , e , $this )
63
65
66
+ let tagList
67
+ let activeIndex
68
+
69
+ if ( [ 'ArrowLeft' , 'ArrowRight' , 'Enter' ] . indexOf ( e . key ) !== - 1 && mode . value === 'tags' ) {
70
+ tagList = [ ...( multiselect . value . querySelectorAll ( `[data-tags] > *` ) || [ ] ) ] . filter ( e => e !== tags . value )
71
+ activeIndex = tagList . findIndex ( e => e === document . activeElement )
72
+ }
73
+
64
74
switch ( e . key ) {
65
75
case 'Backspace' :
66
76
if ( mode . value === 'single' ) {
@@ -81,6 +91,21 @@ export default function useKeyboard (props, context, dep)
81
91
case 'Enter' :
82
92
e . preventDefault ( )
83
93
94
+ if ( activeIndex !== - 1 ) {
95
+ update ( [ ...iv . value ] . filter ( ( v , k ) => k !== activeIndex ) )
96
+
97
+ if ( activeIndex === tagList . length - 1 ) {
98
+ if ( tagList . length - 1 ) {
99
+ tagList [ tagList . length - 2 ] . focus ( )
100
+ } else if ( searchable . value ) {
101
+ tags . value . querySelector ( 'input' ) . focus ( )
102
+ } else {
103
+ multiselect . value . focus ( )
104
+ }
105
+ }
106
+ return
107
+ }
108
+
84
109
if ( addOptionOn . value . indexOf ( 'enter' ) === - 1 && createOption . value ) {
85
110
return
86
111
}
@@ -157,6 +182,44 @@ export default function useKeyboard (props, context, dep)
157
182
158
183
forwardPointer ( )
159
184
break
185
+
186
+ case 'ArrowLeft' :
187
+ if ( ( searchable . value && tags . value . querySelector ( 'input' ) . selectionStart ) || e . shiftKey ) {
188
+ return
189
+ }
190
+
191
+ e . preventDefault ( )
192
+
193
+ if ( mode . value !== 'tags' ) {
194
+ return
195
+ }
196
+
197
+ if ( activeIndex === - 1 ) {
198
+ tagList [ tagList . length - 1 ] . focus ( )
199
+ }
200
+ else if ( activeIndex > 0 ) {
201
+ tagList [ activeIndex - 1 ] . focus ( )
202
+ }
203
+ break
204
+
205
+ case 'ArrowRight' :
206
+ if ( activeIndex === - 1 || e . shiftKey ) {
207
+ return
208
+ }
209
+
210
+ e . preventDefault ( )
211
+
212
+ if ( tagList . length > activeIndex + 1 ) {
213
+ tagList [ activeIndex + 1 ] . focus ( )
214
+ }
215
+ else if ( searchable . value ) {
216
+ tags . value . querySelector ( 'input' ) . focus ( )
217
+ }
218
+ else if ( ! searchable . value ) {
219
+ multiselect . value . focus ( )
220
+ }
221
+
222
+ break
160
223
}
161
224
}
162
225
0 commit comments