@@ -104,6 +104,26 @@ describe('CdkOption and CdkListbox', () => {
104
104
105
105
expect ( optionEls [ 0 ] . getAttribute ( 'tabindex' ) ) . toBe ( '10' ) ;
106
106
} ) ;
107
+
108
+ it ( 'should reset the tabindex if the active option is destroyed' , ( ) => {
109
+ const { fixture, listbox, listboxEl} = setupComponent ( ListboxWithOptions ) ;
110
+ let options = fixture . nativeElement . querySelectorAll ( '.cdk-option' ) ;
111
+ expect ( listboxEl . getAttribute ( 'tabindex' ) ) . toBe ( '0' ) ;
112
+ expect ( options [ 0 ] . getAttribute ( 'tabindex' ) ) . toBe ( '-1' ) ;
113
+
114
+ listbox . focus ( ) ;
115
+ fixture . detectChanges ( ) ;
116
+
117
+ expect ( listboxEl . getAttribute ( 'tabindex' ) ) . toBe ( '-1' ) ;
118
+ expect ( options [ 0 ] . getAttribute ( 'tabindex' ) ) . toBe ( '0' ) ;
119
+
120
+ fixture . componentInstance . appleRendered = false ;
121
+ fixture . detectChanges ( ) ;
122
+ options = fixture . nativeElement . querySelectorAll ( '.cdk-option' ) ;
123
+
124
+ expect ( listboxEl . getAttribute ( 'tabindex' ) ) . toBe ( '0' ) ;
125
+ expect ( options [ 0 ] . getAttribute ( 'tabindex' ) ) . toBe ( '-1' ) ;
126
+ } ) ;
107
127
} ) ;
108
128
109
129
describe ( 'selection' , ( ) => {
@@ -943,12 +963,14 @@ describe('CdkOption and CdkListbox', () => {
943
963
[cdkListboxNavigatesDisabledOptions]="!navigationSkipsDisabled"
944
964
[cdkListboxValue]="selectedValue"
945
965
(cdkListboxValueChange)="onSelectionChange($event)">
946
- <div cdkOption="apple"
947
- [cdkOptionDisabled]="isAppleDisabled"
948
- [id]="appleId"
949
- [tabindex]="appleTabindex">
950
- Apple
951
- </div>
966
+ @if (appleRendered) {
967
+ <div cdkOption="apple"
968
+ [cdkOptionDisabled]="isAppleDisabled"
969
+ [id]="appleId"
970
+ [tabindex]="appleTabindex">
971
+ Apple
972
+ </div>
973
+ }
952
974
<div cdkOption="orange" [cdkOptionDisabled]="isOrangeDisabled">Orange
953
975
</div>
954
976
<div cdkOption="banana">Banana</div>
@@ -965,6 +987,7 @@ class ListboxWithOptions {
965
987
isActiveDescendant = false ;
966
988
navigationWraps = true ;
967
989
navigationSkipsDisabled = true ;
990
+ appleRendered = true ;
968
991
listboxId : string ;
969
992
listboxTabindex : number ;
970
993
appleId : string ;
0 commit comments