@@ -337,6 +337,54 @@ describe('ListBox', () => {
337
337
expect ( getAllByRole ( 'option' ) . map ( o => o . textContent ) ) . toEqual ( [ 'Hi' ] ) ;
338
338
} ) ;
339
339
340
+ it ( 'should update collection when moving item to a different section' , ( ) => {
341
+ let { getAllByRole, rerender} = render (
342
+ < ListBox aria-label = "Test" >
343
+ < ListBoxSection id = "veggies" >
344
+ < Header > Veggies</ Header >
345
+ < ListBoxItem key = "lettuce" id = "lettuce" > Lettuce</ ListBoxItem >
346
+ < ListBoxItem key = "tomato" id = "tomato" > Tomato</ ListBoxItem >
347
+ < ListBoxItem key = "onion" id = "onion" > Onion</ ListBoxItem >
348
+ </ ListBoxSection >
349
+ < ListBoxSection id = "meats" >
350
+ < Header > Meats</ Header >
351
+ < ListBoxItem key = "ham" id = "ham" > Ham</ ListBoxItem >
352
+ < ListBoxItem key = "tuna" id = "tuna" > Tuna</ ListBoxItem >
353
+ < ListBoxItem key = "tofu" id = "tofu" > Tofu</ ListBoxItem >
354
+ </ ListBoxSection >
355
+ </ ListBox >
356
+ ) ;
357
+
358
+ let sections = getAllByRole ( 'group' ) ;
359
+ let items = within ( sections [ 0 ] ) . getAllByRole ( 'option' ) ;
360
+ expect ( items ) . toHaveLength ( 3 ) ;
361
+ items = within ( sections [ 1 ] ) . getAllByRole ( 'option' ) ;
362
+ expect ( items ) . toHaveLength ( 3 ) ;
363
+
364
+ rerender (
365
+ < ListBox aria-label = "Test" >
366
+ < ListBoxSection id = "veggies" >
367
+ < Header > Veggies</ Header >
368
+ < ListBoxItem key = "lettuce" id = "lettuce" > Lettuce</ ListBoxItem >
369
+ < ListBoxItem key = "tomato" id = "tomato" > Tomato</ ListBoxItem >
370
+ < ListBoxItem key = "onion" id = "onion" > Onion</ ListBoxItem >
371
+ < ListBoxItem key = "ham" id = "ham" > Ham</ ListBoxItem >
372
+ </ ListBoxSection >
373
+ < ListBoxSection id = "meats" >
374
+ < Header > Meats</ Header >
375
+ < ListBoxItem key = "tuna" id = "tuna" > Tuna</ ListBoxItem >
376
+ < ListBoxItem key = "tofu" id = "tofu" > Tofu</ ListBoxItem >
377
+ </ ListBoxSection >
378
+ </ ListBox >
379
+ ) ;
380
+
381
+ sections = getAllByRole ( 'group' ) ;
382
+ items = within ( sections [ 0 ] ) . getAllByRole ( 'option' ) ;
383
+ expect ( items ) . toHaveLength ( 4 ) ;
384
+ items = within ( sections [ 1 ] ) . getAllByRole ( 'option' ) ;
385
+ expect ( items ) . toHaveLength ( 2 ) ;
386
+ } ) ;
387
+
340
388
it ( 'should support autoFocus' , ( ) => {
341
389
let { getByRole} = renderListbox ( { autoFocus : true } ) ;
342
390
let listbox = getByRole ( 'listbox' ) ;
0 commit comments