|
1 | 1 | import {Direction, Directionality} from '@angular/cdk/bidi';
|
2 |
| -import {DOWN_ARROW, ENTER, ESCAPE, SPACE, UP_ARROW} from '@angular/cdk/keycodes'; |
| 2 | +import {DOWN_ARROW, ENTER, ESCAPE, SPACE, UP_ARROW, TAB} from '@angular/cdk/keycodes'; |
3 | 3 | import {OverlayContainer} from '@angular/cdk/overlay';
|
4 | 4 | import {map, RxChain, startWith} from '@angular/cdk/rxjs';
|
5 | 5 | import {ScrollDispatcher} from '@angular/cdk/scrolling';
|
6 |
| -import {createKeyboardEvent, dispatchFakeEvent, typeInElement} from '@angular/cdk/testing'; |
| 6 | +import { |
| 7 | + createKeyboardEvent, |
| 8 | + dispatchKeyboardEvent, |
| 9 | + dispatchFakeEvent, |
| 10 | + typeInElement, |
| 11 | +} from '@angular/cdk/testing'; |
7 | 12 | import {
|
8 | 13 | ChangeDetectionStrategy,
|
9 | 14 | Component,
|
@@ -958,6 +963,26 @@ describe('MatAutocomplete', () => {
|
958 | 963 | });
|
959 | 964 | }));
|
960 | 965 |
|
| 966 | + it('should close the panel when tabbing away from a trigger without results', async(() => { |
| 967 | + const trigger = fixture.componentInstance.trigger; |
| 968 | + |
| 969 | + fixture.componentInstance.states = []; |
| 970 | + fixture.componentInstance.filteredStates = []; |
| 971 | + fixture.detectChanges(); |
| 972 | + input.focus(); |
| 973 | + |
| 974 | + fixture.whenStable().then(() => { |
| 975 | + expect(overlayContainerElement.querySelector('.mat-autocomplete-panel')) |
| 976 | + .toBeTruthy('Expected panel to be rendered.'); |
| 977 | + |
| 978 | + dispatchKeyboardEvent(input, 'keydown', TAB); |
| 979 | + fixture.detectChanges(); |
| 980 | + |
| 981 | + expect(overlayContainerElement.querySelector('.mat-autocomplete-panel')) |
| 982 | + .toBeFalsy('Expected panel to be removed.'); |
| 983 | + }); |
| 984 | + })); |
| 985 | + |
961 | 986 | it('should reset the active option when closing with the escape key', fakeAsync(() => {
|
962 | 987 | const trigger = fixture.componentInstance.trigger;
|
963 | 988 |
|
|
0 commit comments