@@ -79,4 +79,35 @@ describe('react-tray', function() {
7979 equal ( document . querySelectorAll ( '.ReactTray__Content' ) . length , 1 ) ;
8080 } , 0 ) ;
8181 } ) ;
82+
83+ describe ( 'maintainFocus prop' , function ( ) {
84+ this . timeout ( 0 ) ;
85+ beforeEach ( function ( done ) {
86+ const props = { isOpen : true , onBlur : function ( ) { } , closeTimeoutMS : 0 , maintainFocus : true } ;
87+ const children = (
88+ < div >
89+ < a href = "#" id = "one" > One</ a >
90+ < a href = "#" id = "two" > Two</ a >
91+ < a href = "#" id = "three" > Three</ a >
92+ </ div >
93+ ) ;
94+ renderTray ( props , children , ( ) => done ( ) ) ;
95+ } ) ;
96+
97+ it ( 'sends focus to the first item if tabbing away from the last element' , function ( ) {
98+ const firstItem = document . querySelector ( '#one' ) ;
99+ const lastItem = document . querySelector ( '#three' ) ;
100+ lastItem . focus ( ) ;
101+ TestUtils . Simulate . keyDown ( document . querySelector ( '.ReactTray__Content' ) , { keyCode : 9 } ) ;
102+ equal ( document . activeElement , firstItem ) ;
103+ } ) ;
104+
105+ it ( 'sends focus to the last item if shift + tabbing from the first item' , function ( ) {
106+ const firstItem = document . querySelector ( '#one' ) ;
107+ const lastItem = document . querySelector ( '#three' ) ;
108+ firstItem . focus ( ) ;
109+ TestUtils . Simulate . keyDown ( document . querySelector ( '.ReactTray__Content' ) , { keyCode : 9 , shiftKey : true } ) ;
110+ equal ( document . activeElement , lastItem ) ;
111+ } ) ;
112+ } ) ;
82113} ) ;
0 commit comments