@@ -104,6 +104,221 @@ describe('useKeyboard', () => {
104
104
expect ( preventMock ) . toHaveBeenCalled ( )
105
105
} )
106
106
107
+ it ( 'should remove last tag if focused on enter' , async ( ) => {
108
+ let select = createSelect ( {
109
+ mode : 'tags' ,
110
+ options : [ 1 , 2 , 3 ] ,
111
+ value : [ 1 , 2 , 3 ] ,
112
+ } , {
113
+ attach : true ,
114
+ } )
115
+
116
+ keydown ( select , 'left' )
117
+ keydown ( select , 'enter' )
118
+
119
+ await nextTick ( )
120
+
121
+ expect ( getValue ( select ) ) . toEqual ( [ 1 , 2 ] )
122
+
123
+ destroy ( select )
124
+ } )
125
+
126
+ it ( 'should put focus to multiselect when last tag removed on enter' , async ( ) => {
127
+ let select = createSelect ( {
128
+ mode : 'tags' ,
129
+ options : [ 1 , 2 , 3 ] ,
130
+ value : [ 1 ] ,
131
+ } , {
132
+ attach : true ,
133
+ } )
134
+
135
+ keydown ( select , 'left' )
136
+ keydown ( select , 'enter' )
137
+
138
+ await nextTick ( )
139
+
140
+ expect ( getValue ( select ) ) . toEqual ( [ ] )
141
+ expect ( document . activeElement ) . toEqual ( select . vm . $el )
142
+
143
+ destroy ( select )
144
+ } )
145
+
146
+ it ( 'should put focus to input when last tag removed when searchable on enter' , async ( ) => {
147
+ let select = createSelect ( {
148
+ mode : 'tags' ,
149
+ options : [ 1 , 2 , 3 ] ,
150
+ value : [ 1 ] ,
151
+ searchable : true ,
152
+ } , {
153
+ attach : true ,
154
+ } )
155
+
156
+ keydown ( select , 'left' )
157
+ keydown ( select , 'enter' )
158
+
159
+ await nextTick ( )
160
+
161
+ expect ( getValue ( select ) ) . toEqual ( [ ] )
162
+ expect ( document . activeElement ) . toEqual ( select . vm . input )
163
+
164
+ destroy ( select )
165
+ } )
166
+
167
+ it ( 'should remove middle tag if focused on enter' , async ( ) => {
168
+ let select = createSelect ( {
169
+ mode : 'tags' ,
170
+ options : [ 1 , 2 , 3 ] ,
171
+ value : [ 1 , 2 , 3 ] ,
172
+ } , {
173
+ attach : true ,
174
+ } )
175
+
176
+ keydown ( select , 'left' )
177
+ keydown ( select , 'left' )
178
+ keydown ( select , 'enter' )
179
+
180
+ await nextTick ( )
181
+
182
+ expect ( getValue ( select ) ) . toEqual ( [ 1 , 3 ] )
183
+
184
+ destroy ( select )
185
+ } )
186
+
187
+ it ( 'should remove first tag if focused on enter' , async ( ) => {
188
+ let select = createSelect ( {
189
+ mode : 'tags' ,
190
+ options : [ 1 , 2 , 3 ] ,
191
+ value : [ 1 , 2 , 3 ] ,
192
+ } , {
193
+ attach : true ,
194
+ } )
195
+
196
+ keydown ( select , 'left' )
197
+ keydown ( select , 'left' )
198
+ keydown ( select , 'left' )
199
+ keydown ( select , 'enter' )
200
+
201
+ await nextTick ( )
202
+
203
+ expect ( getValue ( select ) ) . toEqual ( [ 2 , 3 ] )
204
+
205
+ destroy ( select )
206
+ } )
207
+
208
+
209
+ it ( 'should select pointer if there are no tags' , async ( ) => {
210
+ let select = createSelect ( {
211
+ mode : 'tags' ,
212
+ options : [ 1 , 2 , 3 ] ,
213
+ value : [ ] ,
214
+ } , {
215
+ attach : true ,
216
+ } )
217
+
218
+ select . vm . setPointer ( select . vm . getOption ( 1 ) )
219
+
220
+ keydown ( select , 'left' )
221
+ keydown ( select , 'enter' )
222
+
223
+ await nextTick ( )
224
+
225
+ expect ( getValue ( select ) ) . toEqual ( [ 1 ] )
226
+
227
+ destroy ( select )
228
+ } )
229
+
230
+ it ( 'should select pointer if right is pressed' , async ( ) => {
231
+ let select = createSelect ( {
232
+ mode : 'tags' ,
233
+ options : [ 1 , 2 , 3 ] ,
234
+ value : [ ] ,
235
+ } , {
236
+ attach : true ,
237
+ } )
238
+
239
+ select . vm . setPointer ( select . vm . getOption ( 1 ) )
240
+
241
+ keydown ( select , 'left' )
242
+ keydown ( select , 'enter' )
243
+
244
+ await nextTick ( )
245
+
246
+ expect ( getValue ( select ) ) . toEqual ( [ 1 ] )
247
+
248
+ destroy ( select )
249
+ } )
250
+
251
+ it ( 'should remove middle tag if navigated with right on enter' , async ( ) => {
252
+ let select = createSelect ( {
253
+ mode : 'tags' ,
254
+ options : [ 1 , 2 , 3 ] ,
255
+ value : [ 1 , 2 , 3 ] ,
256
+ } , {
257
+ attach : true ,
258
+ } )
259
+
260
+ keydown ( select , 'left' )
261
+ keydown ( select , 'left' )
262
+ keydown ( select , 'left' )
263
+ keydown ( select , 'right' )
264
+ keydown ( select , 'enter' )
265
+
266
+ await nextTick ( )
267
+
268
+ expect ( getValue ( select ) ) . toEqual ( [ 1 , 3 ] )
269
+
270
+ destroy ( select )
271
+ } )
272
+
273
+ it ( 'should remove last tag if navigated with right on enter' , async ( ) => {
274
+ let select = createSelect ( {
275
+ mode : 'tags' ,
276
+ options : [ 1 , 2 , 3 ] ,
277
+ value : [ 1 , 2 , 3 ] ,
278
+ } , {
279
+ attach : true ,
280
+ } )
281
+
282
+ keydown ( select , 'left' )
283
+ keydown ( select , 'left' )
284
+ keydown ( select , 'left' )
285
+ keydown ( select , 'right' )
286
+ keydown ( select , 'right' )
287
+ keydown ( select , 'enter' )
288
+
289
+ await nextTick ( )
290
+
291
+ expect ( getValue ( select ) ) . toEqual ( [ 1 , 2 ] )
292
+
293
+ destroy ( select )
294
+ } )
295
+
296
+ it ( 'should not remove anything and select pointer if navigated with right' , async ( ) => {
297
+ let select = createSelect ( {
298
+ mode : 'tags' ,
299
+ options : [ 1 , 2 , 3 ] ,
300
+ value : [ ] ,
301
+ } , {
302
+ attach : true ,
303
+ } )
304
+
305
+ select . vm . setPointer ( select . vm . getOption ( 1 ) )
306
+
307
+ keydown ( select , 'left' )
308
+ keydown ( select , 'left' )
309
+ keydown ( select , 'left' )
310
+ keydown ( select , 'right' )
311
+ keydown ( select , 'right' )
312
+ keydown ( select , 'right' )
313
+ keydown ( select , 'enter' )
314
+
315
+ await nextTick ( )
316
+
317
+ expect ( getValue ( select ) ) . toEqual ( [ 1 ] )
318
+
319
+ destroy ( select )
320
+ } )
321
+
107
322
it ( 'should select pointer' , async ( ) => {
108
323
let select = createSelect ( {
109
324
value : 1 ,
@@ -201,6 +416,7 @@ describe('useKeyboard', () => {
201
416
attach : true ,
202
417
} )
203
418
419
+ select . vm . mouseClicked = true
204
420
select . element . focus ( )
205
421
expect ( select . vm . isOpen ) . toBe ( true )
206
422
@@ -899,6 +1115,87 @@ describe('useKeyboard', () => {
899
1115
} )
900
1116
} )
901
1117
1118
+ describe ( 'left' , ( ) => {
1119
+ it ( 'should stay at the first item when first is selected and left is pressed' , async ( ) => {
1120
+ let select = createSelect ( {
1121
+ mode : 'tags' ,
1122
+ options : [ 1 , 2 , 3 ] ,
1123
+ value : [ 1 ] ,
1124
+ } , {
1125
+ attach : true ,
1126
+ } )
1127
+
1128
+ keydown ( select , 'left' )
1129
+ keydown ( select , 'left' )
1130
+
1131
+ await nextTick ( )
1132
+
1133
+ expect ( document . activeElement ) . toEqual ( select . vm . $el . querySelector ( '[data-tags] > *:first-of-type' ) )
1134
+
1135
+ destroy ( select )
1136
+ } )
1137
+ } )
1138
+
1139
+ describe ( 'right' , ( ) => {
1140
+ it ( 'should focus input when searchable and right is pressed on last element' , async ( ) => {
1141
+ let select = createSelect ( {
1142
+ mode : 'tags' ,
1143
+ options : [ 1 , 2 , 3 ] ,
1144
+ value : [ 1 ] ,
1145
+ searchable : true ,
1146
+ } , {
1147
+ attach : true ,
1148
+ } )
1149
+
1150
+ keydown ( select , 'left' )
1151
+ keydown ( select , 'right' )
1152
+
1153
+ await nextTick ( )
1154
+
1155
+ expect ( document . activeElement ) . toEqual ( select . vm . input )
1156
+
1157
+ destroy ( select )
1158
+ } )
1159
+
1160
+ it ( 'should focus multiselect when right is pressed on last element' , async ( ) => {
1161
+ let select = createSelect ( {
1162
+ mode : 'tags' ,
1163
+ options : [ 1 , 2 , 3 ] ,
1164
+ value : [ 1 ] ,
1165
+ } , {
1166
+ attach : true ,
1167
+ } )
1168
+
1169
+ keydown ( select , 'left' )
1170
+ keydown ( select , 'right' )
1171
+
1172
+ await nextTick ( )
1173
+
1174
+ expect ( document . activeElement ) . toEqual ( select . vm . $el )
1175
+
1176
+ destroy ( select )
1177
+ } )
1178
+
1179
+ it ( 'should keep focus on multiselect when right is pressed' , async ( ) => {
1180
+ let select = createSelect ( {
1181
+ mode : 'tags' ,
1182
+ options : [ 1 , 2 , 3 ] ,
1183
+ value : [ 1 ] ,
1184
+ } , {
1185
+ attach : true ,
1186
+ } )
1187
+
1188
+ select . vm . $el . focus ( )
1189
+ keydown ( select , 'right' )
1190
+
1191
+ await nextTick ( )
1192
+
1193
+ expect ( document . activeElement ) . toEqual ( select . vm . $el )
1194
+
1195
+ destroy ( select )
1196
+ } )
1197
+ } )
1198
+
902
1199
describe ( 'handleKeyup' , ( ) => {
903
1200
it ( 'should emit keyup event' , async ( ) => {
904
1201
let select = createSelect ( {
0 commit comments