@@ -393,4 +393,70 @@ describe('OptionList', () => {
393393 } ) ;
394394 expect ( global . scrollToArgs ) . toEqual ( { index : 1 } ) ;
395395 } ) ;
396+
397+ // Test keyboard navigation behavior when maxCount limit is reached
398+ // Verifies that:
399+ // 1. Can navigate between already selected options
400+ // 2. Cannot navigate to unselected options when maxCount is reached
401+ // 3. Navigation wraps around between selected options
402+ it ( 'should allow keyboard navigation on selected options when reach maxCount' , ( ) => {
403+ const onActiveValue = jest . fn ( ) ;
404+ const listRef = React . createRef < RefOptionListProps > ( ) ;
405+
406+ render (
407+ generateList ( {
408+ multiple : true ,
409+ maxCount : 2 ,
410+ options : [
411+ { value : '1' , label : '1' } ,
412+ { value : '2' , label : '2' } ,
413+ { value : '3' , label : '3' } ,
414+ ] ,
415+ values : new Set ( [ '1' , '2' ] ) , // Pre-select first two options
416+ onActiveValue,
417+ ref : listRef ,
418+ } ) ,
419+ ) ;
420+
421+ onActiveValue . mockReset ( ) ;
422+
423+ // Press down key - should move to option '2'
424+ act ( ( ) => {
425+ listRef . current . onKeyDown ( { which : KeyCode . DOWN } as any ) ;
426+ } ) ;
427+ expect ( onActiveValue ) . toHaveBeenCalledWith (
428+ '2' ,
429+ expect . anything ( ) ,
430+ expect . objectContaining ( { source : 'keyboard' } ) ,
431+ ) ;
432+
433+ // Press down key again - should wrap to option '1'
434+ onActiveValue . mockReset ( ) ;
435+ act ( ( ) => {
436+ listRef . current . onKeyDown ( { which : KeyCode . DOWN } as any ) ;
437+ } ) ;
438+ expect ( onActiveValue ) . toHaveBeenCalledWith (
439+ '1' ,
440+ expect . anything ( ) ,
441+ expect . objectContaining ( { source : 'keyboard' } ) ,
442+ ) ;
443+
444+ // Press up key - should move back to option '2'
445+ onActiveValue . mockReset ( ) ;
446+ act ( ( ) => {
447+ listRef . current . onKeyDown ( { which : KeyCode . UP } as any ) ;
448+ } ) ;
449+ expect ( onActiveValue ) . toHaveBeenCalledWith (
450+ '2' ,
451+ expect . anything ( ) ,
452+ expect . objectContaining ( { source : 'keyboard' } ) ,
453+ ) ;
454+
455+ // Press down key - should not activate option '3' since maxCount is reached
456+ onActiveValue . mockReset ( ) ;
457+ act ( ( ) => {
458+ listRef . current . onKeyDown ( { which : KeyCode . DOWN } as any ) ;
459+ } ) ;
460+ expect ( onActiveValue ) . not . toHaveBeenCalledWith ( '3' , expect . anything ( ) , expect . anything ( ) ) ;
461+ } ) ;
396462} ) ;
0 commit comments