@@ -24,6 +24,7 @@ const home = (mods?: ModifierKeys) => createKeyboardEvent('keydown', 36, 'Home',
24
24
const end = ( mods ?: ModifierKeys ) => createKeyboardEvent ( 'keydown' , 35 , 'End' , mods ) ;
25
25
const space = ( mods ?: ModifierKeys ) => createKeyboardEvent ( 'keydown' , 32 , ' ' , mods ) ;
26
26
const enter = ( mods ?: ModifierKeys ) => createKeyboardEvent ( 'keydown' , 13 , 'Enter' , mods ) ;
27
+ const shift = ( ) => createKeyboardEvent ( 'keydown' , 16 , 'Shift' , { shift : true } ) ;
27
28
28
29
describe ( 'Listbox Pattern' , ( ) => {
29
30
function getListbox ( inputs : Partial < TestInputs > & Pick < TestInputs , 'items' > ) {
@@ -279,18 +280,25 @@ describe('Listbox Pattern', () => {
279
280
expect ( listbox . inputs . value ( ) ) . toEqual ( [ 'Apple' , 'Apricot' ] ) ;
280
281
} ) ;
281
282
282
- it ( 'should toggle the selected state of the next option on Shift + ArrowDown' , ( ) => {
283
+ it ( 'should select a range of options on Shift + ArrowDown/ArrowUp' , ( ) => {
284
+ listbox . onKeydown ( shift ( ) ) ;
283
285
listbox . onKeydown ( down ( { shift : true } ) ) ;
286
+ expect ( listbox . inputs . value ( ) ) . toEqual ( [ 'Apple' , 'Apricot' ] ) ;
284
287
listbox . onKeydown ( down ( { shift : true } ) ) ;
285
- expect ( listbox . inputs . value ( ) ) . toEqual ( [ 'Apricot' , 'Banana' ] ) ;
288
+ expect ( listbox . inputs . value ( ) ) . toEqual ( [ 'Apple' , 'Apricot' , 'Banana' ] ) ;
289
+ listbox . onKeydown ( up ( { shift : true } ) ) ;
290
+ expect ( listbox . inputs . value ( ) ) . toEqual ( [ 'Apple' , 'Apricot' ] ) ;
291
+ listbox . onKeydown ( up ( { shift : true } ) ) ;
292
+ expect ( listbox . inputs . value ( ) ) . toEqual ( [ 'Apple' ] ) ;
286
293
} ) ;
287
294
288
- it ( 'should toggle the selected state of the next option on Shift + ArrowUp ' , ( ) => {
289
- listbox . onKeydown ( down ( ) ) ;
290
- listbox . onKeydown ( down ( ) ) ;
295
+ it ( 'should not allow wrapping while Shift is held down ' , ( ) => {
296
+ listbox . onKeydown ( shift ( ) ) ;
297
+ listbox . onKeydown ( up ( { shift : true } ) ) ;
291
298
listbox . onKeydown ( up ( { shift : true } ) ) ;
292
299
listbox . onKeydown ( up ( { shift : true } ) ) ;
293
- expect ( listbox . inputs . value ( ) ) . toEqual ( [ 'Apricot' , 'Apple' ] ) ;
300
+ listbox . onKeydown ( up ( { shift : true } ) ) ;
301
+ expect ( listbox . inputs . value ( ) ) . toEqual ( [ 'Apple' ] ) ;
294
302
} ) ;
295
303
296
304
it ( 'should select contiguous items from the most recently selected item to the focused item on Shift + Space (or Enter)' , ( ) => {
@@ -385,18 +393,25 @@ describe('Listbox Pattern', () => {
385
393
expect ( listbox . inputs . value ( ) ) . toEqual ( [ 'Apple' , 'Banana' ] ) ;
386
394
} ) ;
387
395
388
- it ( 'should toggle the selected state of the next option on Shift + ArrowDown' , ( ) => {
396
+ it ( 'should select a range of options on Shift + ArrowDown/ArrowUp' , ( ) => {
397
+ listbox . onKeydown ( shift ( ) ) ;
389
398
listbox . onKeydown ( down ( { shift : true } ) ) ;
399
+ expect ( listbox . inputs . value ( ) ) . toEqual ( [ 'Apple' , 'Apricot' ] ) ;
390
400
listbox . onKeydown ( down ( { shift : true } ) ) ;
391
401
expect ( listbox . inputs . value ( ) ) . toEqual ( [ 'Apple' , 'Apricot' , 'Banana' ] ) ;
402
+ listbox . onKeydown ( up ( { shift : true } ) ) ;
403
+ expect ( listbox . inputs . value ( ) ) . toEqual ( [ 'Apple' , 'Apricot' ] ) ;
404
+ listbox . onKeydown ( up ( { shift : true } ) ) ;
405
+ expect ( listbox . inputs . value ( ) ) . toEqual ( [ 'Apple' ] ) ;
392
406
} ) ;
393
407
394
- it ( 'should toggle the selected state of the next option on Shift + ArrowUp ' , ( ) => {
395
- listbox . onKeydown ( down ( ) ) ;
396
- listbox . onKeydown ( down ( ) ) ;
408
+ it ( 'should not allow wrapping while Shift is held down ' , ( ) => {
409
+ listbox . onKeydown ( shift ( ) ) ;
410
+ listbox . onKeydown ( up ( { shift : true } ) ) ;
397
411
listbox . onKeydown ( up ( { shift : true } ) ) ;
398
412
listbox . onKeydown ( up ( { shift : true } ) ) ;
399
- expect ( listbox . inputs . value ( ) ) . toEqual ( [ 'Banana' , 'Apricot' , 'Apple' ] ) ;
413
+ listbox . onKeydown ( up ( { shift : true } ) ) ;
414
+ expect ( listbox . inputs . value ( ) ) . toEqual ( [ 'Apple' ] ) ;
400
415
} ) ;
401
416
402
417
it ( 'should select contiguous items from the most recently selected item to the focused item on Shift + Space (or Enter)' , ( ) => {
0 commit comments