@@ -4,6 +4,7 @@ import { DataGrid, SelectColumn } from '../../src';
44import type { Column } from '../../src' ;
55import {
66 getRowWithCell ,
7+ safeTab ,
78 scrollGrid ,
89 setup ,
910 tabIntoGrid ,
@@ -40,11 +41,11 @@ test('keyboard navigation', async () => {
4041 await validateCellPosition ( 0 , 0 ) ;
4142
4243 // tab to the next cell
43- await userEvent . tab ( ) ;
44+ await safeTab ( ) ;
4445 await validateCellPosition ( 1 , 0 ) ;
4546
4647 // tab back to the previous cell
47- await userEvent . tab ( { shift : true } ) ;
48+ await safeTab ( true ) ;
4849 await validateCellPosition ( 0 , 0 ) ;
4950
5051 // arrow navigation
@@ -97,11 +98,11 @@ test('keyboard navigation', async () => {
9798
9899 // tab at the end of a row selects the first cell on the next row
99100 await userEvent . keyboard ( '{end}' ) ;
100- await userEvent . tab ( ) ;
101+ await safeTab ( ) ;
101102 await validateCellPosition ( 0 , 1 ) ;
102103
103104 // shift tab should select the last cell of the previous row
104- await userEvent . tab ( { shift : true } ) ;
105+ await safeTab ( true ) ;
105106 await validateCellPosition ( 6 , 0 ) ;
106107} ) ;
107108
@@ -122,11 +123,11 @@ test('arrow and tab navigation', async () => {
122123 await validateCellPosition ( 6 , 1 ) ;
123124
124125 // pressing tab on the rightmost cell navigates to the leftmost cell on the next row
125- await userEvent . tab ( ) ;
126+ await safeTab ( ) ;
126127 await validateCellPosition ( 0 , 2 ) ;
127128
128129 // pressing shift+tab on the leftmost cell navigates to the rightmost cell on the previous row
129- await userEvent . tab ( { shift : true } ) ;
130+ await safeTab ( true ) ;
130131 await validateCellPosition ( 6 , 1 ) ;
131132} ) ;
132133
@@ -144,10 +145,10 @@ test('grid enter/exit', async () => {
144145 await validateCellPosition ( 0 , 0 ) ;
145146
146147 // shift+tab tabs out of the grid if we are at the first cell
147- await userEvent . tab ( { shift : true } ) ;
148+ await safeTab ( true ) ;
148149 await expect . element ( beforeButton ) . toHaveFocus ( ) ;
149150
150- await userEvent . tab ( ) ;
151+ await safeTab ( ) ;
151152 await validateCellPosition ( 0 , 0 ) ;
152153
153154 await userEvent . keyboard ( '{arrowdown}{arrowdown}' ) ;
@@ -156,19 +157,19 @@ test('grid enter/exit', async () => {
156157 // tab should select the last selected cell
157158 // click outside the grid
158159 await userEvent . click ( beforeButton ) ;
159- await userEvent . tab ( ) ;
160+ await safeTab ( ) ;
160161 await userEvent . keyboard ( '{arrowdown}' ) ;
161162 await validateCellPosition ( 0 , 3 ) ;
162163
163164 // shift+tab should select the last selected cell
164165 await userEvent . click ( afterButton ) ;
165- await userEvent . tab ( { shift : true } ) ;
166+ await safeTab ( true ) ;
166167 await validateCellPosition ( 0 , 3 ) ;
167168 await expect . element ( selectedCell . getByRole ( 'checkbox' ) ) . toHaveFocus ( ) ;
168169
169170 // tab tabs out of the grid if we are at the last cell
170171 await userEvent . keyboard ( '{Control>}{end}{/Control}' ) ;
171- await userEvent . tab ( ) ;
172+ await safeTab ( ) ;
172173 await expect . element ( afterButton ) . toHaveFocus ( ) ;
173174} ) ;
174175
@@ -184,7 +185,7 @@ test('navigation with focusable cell renderer', async () => {
184185 await expect . element ( checkbox ) . toHaveFocus ( ) ;
185186 await expect . element ( checkbox ) . toHaveAttribute ( 'tabIndex' , '0' ) ;
186187
187- await userEvent . tab ( ) ;
188+ await safeTab ( ) ;
188189 await validateCellPosition ( 1 , 1 ) ;
189190 // cell should set tabIndex to 0 if it does not have focusable cell renderer
190191 await expect . element ( selectedCell ) . toHaveAttribute ( 'tabIndex' , '0' ) ;
@@ -223,31 +224,31 @@ test('navigation when header and summary rows have focusable elements', async ()
223224 // should set focus on the header filter
224225 await expect . element ( page . getByTestId ( 'header-filter1' ) ) . toHaveFocus ( ) ;
225226
226- await userEvent . tab ( ) ;
227+ await safeTab ( ) ;
227228 await expect . element ( page . getByTestId ( 'header-filter2' ) ) . toHaveFocus ( ) ;
228229
229- await userEvent . tab ( ) ;
230+ await safeTab ( ) ;
230231 await validateCellPosition ( 0 , 1 ) ;
231232
232- await userEvent . tab ( { shift : true } ) ;
233+ await safeTab ( true ) ;
233234 await expect . element ( page . getByTestId ( 'header-filter2' ) ) . toHaveFocus ( ) ;
234235
235- await userEvent . tab ( { shift : true } ) ;
236+ await safeTab ( true ) ;
236237 await expect . element ( page . getByTestId ( 'header-filter1' ) ) . toHaveFocus ( ) ;
237238
238- await userEvent . tab ( ) ;
239- await userEvent . tab ( ) ;
239+ await safeTab ( ) ;
240+ await safeTab ( ) ;
240241 await userEvent . keyboard ( '{Control>}{end}{/Control}{arrowup}{arrowup}' ) ;
241242 await validateCellPosition ( 1 , 2 ) ;
242243
243- await userEvent . tab ( ) ;
244+ await safeTab ( ) ;
244245 await expect . element ( page . getByTestId ( 'summary-col2-1' ) ) . toHaveFocus ( ) ;
245246
246- await userEvent . tab ( ) ;
247+ await safeTab ( ) ;
247248 await expect . element ( page . getByTestId ( 'summary-col3-1' ) ) . toHaveFocus ( ) ;
248249
249- await userEvent . tab ( { shift : true } ) ;
250- await userEvent . tab ( { shift : true } ) ;
250+ await safeTab ( true ) ;
251+ await safeTab ( true ) ;
251252 await validateCellPosition ( 1 , 2 ) ;
252253 await expect . element ( selectedCell ) . toHaveFocus ( ) ;
253254} ) ;
@@ -297,7 +298,7 @@ test('reset selected cell when column is removed', async () => {
297298
298299 const { rerender } = await page . render ( < Test columns = { columns } /> ) ;
299300
300- await userEvent . tab ( ) ;
301+ await safeTab ( ) ;
301302 await userEvent . keyboard ( '{arrowdown}{arrowright}' ) ;
302303 await validateCellPosition ( 1 , 1 ) ;
303304
@@ -319,7 +320,7 @@ test('reset selected cell when row is removed', async () => {
319320
320321 const { rerender } = await page . render ( < Test rows = { rows } /> ) ;
321322
322- await userEvent . tab ( ) ;
323+ await safeTab ( ) ;
323324 await userEvent . keyboard ( '{arrowdown}{arrowdown}{arrowright}' ) ;
324325 await validateCellPosition ( 1 , 2 ) ;
325326
@@ -332,7 +333,7 @@ test('should not change the left and right arrow behavior for right to left lang
332333 await setup < Row , Row > ( { columns, rows, direction : 'rtl' } , true ) ;
333334 await tabIntoGrid ( ) ;
334335 await validateCellPosition ( 0 , 0 ) ;
335- await userEvent . tab ( ) ;
336+ await safeTab ( ) ;
336337 await validateCellPosition ( 1 , 0 ) ;
337338 await userEvent . keyboard ( '{arrowright}' ) ;
338339 await validateCellPosition ( 0 , 0 ) ;
0 commit comments