diff --git a/src/cdk/listbox/listbox.spec.ts b/src/cdk/listbox/listbox.spec.ts index a7a2c9837ce1..e8eef7b82dc5 100644 --- a/src/cdk/listbox/listbox.spec.ts +++ b/src/cdk/listbox/listbox.spec.ts @@ -104,6 +104,26 @@ describe('CdkOption and CdkListbox', () => { expect(optionEls[0].getAttribute('tabindex')).toBe('10'); }); + + it('should reset the tabindex if the active option is destroyed', () => { + const {fixture, listbox, listboxEl} = setupComponent(ListboxWithOptions); + let options = fixture.nativeElement.querySelectorAll('.cdk-option'); + expect(listboxEl.getAttribute('tabindex')).toBe('0'); + expect(options[0].getAttribute('tabindex')).toBe('-1'); + + listbox.focus(); + fixture.detectChanges(); + + expect(listboxEl.getAttribute('tabindex')).toBe('-1'); + expect(options[0].getAttribute('tabindex')).toBe('0'); + + fixture.componentInstance.appleRendered = false; + fixture.detectChanges(); + options = fixture.nativeElement.querySelectorAll('.cdk-option'); + + expect(listboxEl.getAttribute('tabindex')).toBe('0'); + expect(options[0].getAttribute('tabindex')).toBe('-1'); + }); }); describe('selection', () => { @@ -943,12 +963,14 @@ describe('CdkOption and CdkListbox', () => { [cdkListboxNavigatesDisabledOptions]="!navigationSkipsDisabled" [cdkListboxValue]="selectedValue" (cdkListboxValueChange)="onSelectionChange($event)"> -