@@ -649,3 +649,105 @@ it('Shoud move to tabbable elements if onlyTabbable', async () => {
649
649
650
650
controller . abort ( )
651
651
} )
652
+
653
+ it ( 'Should ignore hidden elements after focus zone is enabled' , async ( ) => {
654
+ const user = userEvent . setup ( )
655
+ const { container, rerender} = render (
656
+ < div id = "focusZone" >
657
+ < button tabIndex = { 0 } > Apple</ button >
658
+ < button tabIndex = { 0 } > Banana</ button >
659
+ < button tabIndex = { 0 } > Cantaloupe</ button >
660
+ </ div > ,
661
+ )
662
+
663
+ const focusZoneContainer = container . querySelector < HTMLElement > ( '#focusZone' ) !
664
+ const [ firstButton , , thirdButton ] = focusZoneContainer . querySelectorAll ( 'button' )
665
+ const controller = focusZone ( focusZoneContainer )
666
+
667
+ firstButton . focus ( )
668
+ expect ( document . activeElement ) . toEqual ( firstButton )
669
+
670
+ rerender (
671
+ < div id = "focusZone" >
672
+ < button tabIndex = { 0 } > Apple</ button >
673
+ < button tabIndex = { 0 } hidden >
674
+ Banana
675
+ </ button >
676
+ < button tabIndex = { 0 } > Cantaloupe</ button >
677
+ </ div > ,
678
+ )
679
+
680
+ await user . keyboard ( '{arrowdown}' )
681
+ expect ( document . activeElement ) . toEqual ( thirdButton )
682
+
683
+ controller . abort ( )
684
+ } )
685
+
686
+ it ( 'Should respect unhidden elements after focus zone is enabled' , async ( ) => {
687
+ const user = userEvent . setup ( )
688
+ const { container, rerender} = render (
689
+ < div id = "focusZone" >
690
+ < button tabIndex = { 0 } > Apple</ button >
691
+ < button tabIndex = { 0 } hidden >
692
+ Banana
693
+ </ button >
694
+ < button tabIndex = { 0 } > Cantaloupe</ button >
695
+ </ div > ,
696
+ )
697
+
698
+ const focusZoneContainer = container . querySelector < HTMLElement > ( '#focusZone' ) !
699
+ const [ firstButton , secondButton , thirdButton ] = focusZoneContainer . querySelectorAll ( 'button' )
700
+ const controller = focusZone ( focusZoneContainer )
701
+
702
+ firstButton . focus ( )
703
+ expect ( document . activeElement ) . toEqual ( firstButton )
704
+
705
+ await user . keyboard ( '{arrowdown}' )
706
+ expect ( document . activeElement ) . toEqual ( thirdButton )
707
+
708
+ rerender (
709
+ < div id = "focusZone" >
710
+ < button tabIndex = { 0 } > Apple</ button >
711
+ < button tabIndex = { 0 } > Banana</ button >
712
+ < button tabIndex = { 0 } > Cantaloupe</ button >
713
+ </ div > ,
714
+ )
715
+
716
+ await user . keyboard ( '{arrowup}' )
717
+ expect ( document . activeElement ) . toEqual ( secondButton )
718
+
719
+ controller . abort ( )
720
+ } )
721
+
722
+ it ( 'Should ignore disabled elements after focus zone is enabled' , async ( ) => {
723
+ const user = userEvent . setup ( )
724
+ const { container, rerender} = render (
725
+ < div id = "focusZone" >
726
+ < button tabIndex = { 0 } > Apple</ button >
727
+ < button tabIndex = { 0 } > Banana</ button >
728
+ < button tabIndex = { 0 } > Cantaloupe</ button >
729
+ </ div > ,
730
+ )
731
+
732
+ const focusZoneContainer = container . querySelector < HTMLElement > ( '#focusZone' ) !
733
+ const [ firstButton , , thirdButton ] = focusZoneContainer . querySelectorAll ( 'button' )
734
+ const controller = focusZone ( focusZoneContainer )
735
+
736
+ firstButton . focus ( )
737
+ expect ( document . activeElement ) . toEqual ( firstButton )
738
+
739
+ rerender (
740
+ < div id = "focusZone" >
741
+ < button tabIndex = { 0 } > Apple</ button >
742
+ < button tabIndex = { 0 } disabled >
743
+ Banana
744
+ </ button >
745
+ < button tabIndex = { 0 } > Cantaloupe</ button >
746
+ </ div > ,
747
+ )
748
+
749
+ await user . keyboard ( '{arrowdown}' )
750
+ expect ( document . activeElement ) . toEqual ( thirdButton )
751
+
752
+ controller . abort ( )
753
+ } )
0 commit comments