@@ -96,6 +96,7 @@ describe('Grid directives', () => {
9696 enableSelection ?: boolean ;
9797 selectionMode ?: 'follow' | 'explicit' ;
9898 gridData ?: RowConfig [ ] ;
99+ tabIndex ?: number ;
99100 } ) {
100101 TestBed . resetTestingModule ( ) ;
101102 TestBed . configureTestingModule ( { } ) ;
@@ -111,6 +112,7 @@ describe('Grid directives', () => {
111112 if ( opts ?. enableSelection !== undefined )
112113 testComponent . enableSelection . set ( opts . enableSelection ) ;
113114 if ( opts ?. selectionMode !== undefined ) testComponent . selectionMode . set ( opts . selectionMode ) ;
115+ if ( opts ?. tabIndex !== undefined ) testComponent . tabIndex . set ( opts . tabIndex ) ;
114116
115117 if ( opts ?. gridData !== undefined ) {
116118 testComponent . gridData . set ( opts . gridData ) ;
@@ -161,14 +163,25 @@ describe('Grid directives', () => {
161163 } ) ;
162164
163165 describe ( 'focus management' , ( ) => {
164- it ( 'should set tabindex based on the pattern tabIndex' , ( ) => {
166+ it ( 'should set tabindex based on the pattern tabIndex' , async ( ) => {
165167 setupGrid ( { focusMode : 'roving' } ) ;
168+ gridInstance . _pattern . setDefaultStateEffect ( ) ;
169+ fixture . detectChanges ( ) ;
170+ await fixture . whenStable ( ) ;
166171 expect ( gridElement . getAttribute ( 'tabindex' ) ) . toBe ( '-1' ) ; // roving defaults to -1 on host
167172
168173 setupGrid ( { focusMode : 'activedescendant' } ) ;
174+ gridInstance . _pattern . setDefaultStateEffect ( ) ;
175+ fixture . detectChanges ( ) ;
176+ await fixture . whenStable ( ) ;
169177 expect ( gridElement . getAttribute ( 'tabindex' ) ) . toBe ( '0' ) ; // activedescendant defaults to 0 on host
170178 } ) ;
171179
180+ it ( 'should be able to override tabindex' , ( ) => {
181+ setupGrid ( { focusMode : 'activedescendant' , tabIndex : - 1 } ) ;
182+ expect ( gridElement . getAttribute ( 'tabindex' ) ) . toBe ( '-1' ) ;
183+ } ) ;
184+
172185 it ( 'should activate the cell when the grid receives focusin' , ( ) => {
173186 setupGrid ( ) ;
174187
@@ -960,7 +973,8 @@ describe('Grid directives', () => {
960973 [focusMode]="focusMode()"
961974 [softDisabled]="softDisabled()"
962975 [enableSelection]="enableSelection()"
963- [selectionMode]="selectionMode()">
976+ [selectionMode]="selectionMode()"
977+ [tabIndex]="tabIndex()">
964978 @for (row of gridData(); track $index; let rIndex = $index) {
965979 <tr ngGridRow [rowIndex]="row.rowIndex">
966980 @for (cell of row.cells; track $index; let cIndex = $index) {
@@ -1018,6 +1032,7 @@ class GridTestComponent {
10181032 readonly enableSelection = signal ( false ) ;
10191033 readonly selectionMode = signal < 'follow' | 'explicit' > ( 'follow' ) ;
10201034 readonly gridData = signal < RowConfig [ ] > ( createGridData ( ) ) ;
1035+ readonly tabIndex = signal < number | undefined > ( undefined ) ;
10211036
10221037 onActivated = jasmine . createSpy ( 'activated' ) ;
10231038 onDeactivated = jasmine . createSpy ( 'deactivated' ) ;
0 commit comments