@@ -99,19 +99,17 @@ function getTabbableRows(root) {
9999 return root . querySelectorAll ( 'tr[tabindex]:not([hidden]):not([tabindex="-1"])' ) ;
100100}
101101
102- function hierarchicalDataProvider ( { parentItem } , callback ) {
103- // Let's use a count lower than pageSize so we can ignore page + pageSize for now
104- const itemsOnEachLevel = 5 ;
105-
106- const items = [ ...Array ( itemsOnEachLevel ) ] . map ( ( _ , i ) => {
102+ function hierarchicalDataProvider ( { parentItem, page, pageSize } , callback ) {
103+ const items = Array . from ( { length : 100 } , ( _ , i ) => {
107104 return {
108105 name : `${ parentItem ? `${ parentItem . name } -` : '' } ${ i } ` ,
109106 // Let's only have child items on every second item
110107 children : i % 2 === 0 ,
111108 } ;
112109 } ) ;
113110
114- callback ( items , itemsOnEachLevel ) ;
111+ const offset = page * pageSize ;
112+ callback ( items . slice ( offset , offset + pageSize ) , items . length ) ;
115113}
116114
117115describe ( 'keyboard navigation - row focus' , ( ) => {
@@ -145,6 +143,39 @@ describe('keyboard navigation - row focus', () => {
145143 await nextRender ( grid ) ;
146144 } ) ;
147145
146+ describe ( 'scrolling and navigating' , ( ) => {
147+ it ( 'should scroll focused nested row into view on arrow key' , ( ) => {
148+ focusItem ( 0 ) ;
149+ // Expand first row
150+ right ( ) ;
151+ // Focus first nested row
152+ down ( ) ;
153+ // Simulate real scrolling to get the virtualizer to render
154+ // the focused item in a different element.
155+ grid . $ . table . scrollTop = grid . $ . table . scrollHeight / 2 ;
156+ flushGrid ( grid ) ;
157+ down ( ) ;
158+ expect ( getFocusedRowIndex ( grid ) ) . to . equal ( 2 ) ;
159+ } ) ;
160+
161+ it ( 'should scroll focused nested row into view on Tab' , ( ) => {
162+ focusItem ( 0 ) ;
163+ // Expand first row
164+ right ( ) ;
165+ // Focus first nested row
166+ down ( ) ;
167+ // Move focus to header
168+ shiftTab ( ) ;
169+ // Simulate real scrolling to get the virtualizer to render
170+ // the focused item in a different element.
171+ grid . $ . table . scrollTop = grid . $ . table . scrollHeight / 2 ;
172+ flushGrid ( grid ) ;
173+ // Move focus back to items
174+ tab ( ) ;
175+ expect ( getFocusedRowIndex ( grid ) ) . to . equal ( 1 ) ;
176+ } ) ;
177+ } ) ;
178+
148179 describe ( 'navigating with tab' , ( ) => {
149180 it ( 'should have single tabbable row in every section' , ( ) => {
150181 const tabbableElements = getTabbableElements ( grid . shadowRoot ) ;
@@ -339,7 +370,7 @@ describe('keyboard navigation - row focus', () => {
339370
340371 end ( ) ;
341372
342- expect ( getFocusedRowIndex ( grid ) ) . to . equal ( 4 ) ;
373+ expect ( getFocusedRowIndex ( grid ) ) . to . equal ( 99 ) ;
343374 } ) ;
344375 } ) ;
345376 } ) ;
0 commit comments