@@ -7,12 +7,13 @@ import {
77 safeTab ,
88 scrollGrid ,
99 setup ,
10- tabIntoGrid ,
1110 testCount ,
1211 validateCellPosition
1312} from './utils' ;
1413
1514const activeCell = page . getActiveCell ( ) ;
15+ const activeSelectAllCheckbox = activeCell . getSelectAllCheckbox ( ) ;
16+ const activeSelectCheckbox = activeCell . getByRole ( 'checkbox' , { name : 'Select' , exact : true } ) ;
1617
1718type Row = undefined ;
1819
@@ -31,13 +32,13 @@ const columns: readonly Column<Row, Row>[] = [
3132] ;
3233
3334test ( 'keyboard navigation' , async ( ) => {
34- await setup ( { columns, rows, topSummaryRows, bottomSummaryRows } , true ) ;
35+ await setup ( { columns, rows, topSummaryRows, bottomSummaryRows } ) ;
3536
3637 // no initial active position
3738 await expect . element ( activeCell ) . not . toBeInTheDocument ( ) ;
3839
3940 // tab into the grid
40- await tabIntoGrid ( ) ;
41+ await safeTab ( ) ;
4142 await validateCellPosition ( 0 , 0 ) ;
4243
4344 // tab to the next cell
@@ -107,10 +108,10 @@ test('keyboard navigation', async () => {
107108} ) ;
108109
109110test ( 'arrow and tab navigation' , async ( ) => {
110- await setup ( { columns, rows, bottomSummaryRows } , true ) ;
111+ await setup ( { columns, rows, bottomSummaryRows } ) ;
111112
112113 // pressing arrowleft on the leftmost cell does nothing
113- await tabIntoGrid ( ) ;
114+ await safeTab ( ) ;
114115 await userEvent . keyboard ( '{arrowdown}' ) ;
115116 await validateCellPosition ( 0 , 1 ) ;
116117 await userEvent . keyboard ( '{arrowleft}' ) ;
@@ -132,7 +133,17 @@ test('arrow and tab navigation', async () => {
132133} ) ;
133134
134135test ( 'grid enter/exit' , async ( ) => {
135- await setup < Row , Row > ( { columns, rows : Array . from ( { length : 5 } ) , bottomSummaryRows } , true ) ;
136+ await page . render (
137+ < >
138+ < button type = "button" > Before</ button >
139+ < DataGrid
140+ columns = { columns }
141+ rows = { Array . from < Row > ( { length : 5 } ) }
142+ bottomSummaryRows = { bottomSummaryRows }
143+ />
144+ < button type = "button" > After</ button >
145+ </ >
146+ ) ;
136147
137148 const beforeButton = page . getByRole ( 'button' , { name : 'Before' } ) ;
138149 const afterButton = page . getByRole ( 'button' , { name : 'After' } ) ;
@@ -141,31 +152,37 @@ test('grid enter/exit', async () => {
141152 await expect . element ( activeCell ) . not . toBeInTheDocument ( ) ;
142153
143154 // tab into the grid
144- await tabIntoGrid ( ) ;
155+ await safeTab ( ) ;
156+ await safeTab ( ) ;
145157 await validateCellPosition ( 0 , 0 ) ;
158+ await expect . element ( activeSelectAllCheckbox ) . toHaveFocus ( ) ;
146159
147160 // shift+tab tabs out of the grid if we are at the first cell
148161 await safeTab ( true ) ;
149162 await expect . element ( beforeButton ) . toHaveFocus ( ) ;
150163
151164 await safeTab ( ) ;
152165 await validateCellPosition ( 0 , 0 ) ;
166+ await expect . element ( activeSelectAllCheckbox ) . toHaveFocus ( ) ;
153167
154168 await userEvent . keyboard ( '{arrowdown}{arrowdown}' ) ;
155169 await validateCellPosition ( 0 , 2 ) ;
170+ await expect . element ( activeSelectCheckbox ) . toHaveFocus ( ) ;
156171
157172 // tab should focus the last active cell
158173 // click outside the grid
159174 await userEvent . click ( beforeButton ) ;
160175 await safeTab ( ) ;
161176 await userEvent . keyboard ( '{arrowdown}' ) ;
162177 await validateCellPosition ( 0 , 3 ) ;
178+ await expect . element ( activeSelectCheckbox ) . toHaveFocus ( ) ;
163179
164180 // shift+tab should focus the last active cell
181+ // click outside the grid
165182 await userEvent . click ( afterButton ) ;
166183 await safeTab ( true ) ;
167184 await validateCellPosition ( 0 , 3 ) ;
168- await expect . element ( activeCell . getByRole ( 'checkbox' ) ) . toHaveFocus ( ) ;
185+ await expect . element ( activeSelectCheckbox ) . toHaveFocus ( ) ;
169186
170187 // tab tabs out of the grid if we are at the last cell
171188 await userEvent . keyboard ( '{Control>}{end}{/Control}' ) ;
@@ -174,16 +191,15 @@ test('grid enter/exit', async () => {
174191} ) ;
175192
176193test ( 'navigation with focusable cell renderer' , async ( ) => {
177- await setup < Row , Row > ( { columns, rows : Array . from ( { length : 1 } ) , bottomSummaryRows } , true ) ;
178- await tabIntoGrid ( ) ;
194+ await setup ( { columns, rows : Array . from < Row > ( { length : 1 } ) , bottomSummaryRows } ) ;
195+ await safeTab ( ) ;
179196 await userEvent . keyboard ( '{arrowdown}' ) ;
180197 await validateCellPosition ( 0 , 1 ) ;
181198
182199 // cell should not set tabIndex to 0 if it contains a focusable cell renderer
183200 await expect . element ( activeCell ) . toHaveAttribute ( 'tabIndex' , '-1' ) ;
184- const checkbox = activeCell . getByRole ( 'checkbox' ) ;
185- await expect . element ( checkbox ) . toHaveFocus ( ) ;
186- await expect . element ( checkbox ) . toHaveAttribute ( 'tabIndex' , '0' ) ;
201+ await expect . element ( activeSelectCheckbox ) . toHaveFocus ( ) ;
202+ await expect . element ( activeSelectCheckbox ) . toHaveAttribute ( 'tabIndex' , '0' ) ;
187203
188204 await safeTab ( ) ;
189205 await validateCellPosition ( 1 , 1 ) ;
@@ -215,11 +231,8 @@ test('navigation when header and summary rows have focusable elements', async ()
215231 }
216232 ] ;
217233
218- await setup < Row , number > (
219- { columns, rows : Array . from ( { length : 2 } ) , bottomSummaryRows : [ 1 , 2 ] } ,
220- true
221- ) ;
222- await tabIntoGrid ( ) ;
234+ await setup ( { columns, rows : Array . from < Row > ( { length : 2 } ) , bottomSummaryRows : [ 1 , 2 ] } ) ;
235+ await safeTab ( ) ;
223236
224237 // should set focus on the header filter
225238 await expect . element ( page . getByTestId ( 'header-filter1' ) ) . toHaveFocus ( ) ;
@@ -259,8 +272,8 @@ test('navigation when active cell not in the viewport', async () => {
259272 for ( let i = 0 ; i < 99 ; i ++ ) {
260273 columns . push ( { key : `col${ i } ` , name : `col${ i } ` , frozen : i < 5 } ) ;
261274 }
262- await setup ( { columns, rows, bottomSummaryRows } , true ) ;
263- await tabIntoGrid ( ) ;
275+ await setup ( { columns, rows, bottomSummaryRows } ) ;
276+ await safeTab ( ) ;
264277 await validateCellPosition ( 0 , 0 ) ;
265278
266279 await userEvent . keyboard ( '{Control>}{end}{/Control}{arrowup}{arrowup}' ) ;
@@ -330,8 +343,8 @@ test('reset active cell when row is removed', async () => {
330343} ) ;
331344
332345test ( 'should not change the left and right arrow behavior for right to left languages' , async ( ) => {
333- await setup < Row , Row > ( { columns, rows, direction : 'rtl' } , true ) ;
334- await tabIntoGrid ( ) ;
346+ await setup < Row , Row > ( { columns, rows, direction : 'rtl' } ) ;
347+ await safeTab ( ) ;
335348 await validateCellPosition ( 0 , 0 ) ;
336349 await safeTab ( ) ;
337350 await validateCellPosition ( 1 , 0 ) ;
0 commit comments