Skip to content

Commit

Permalink
fix(autocomplete): panelClosingActions emitting when tabbing away fro…
Browse files Browse the repository at this point in the history
…m a closed autocomplete (#8774)

Fixes the `MatAutocompleteTrigger.panelClosingActions` emitting when the user tabs away from an autocomplete that was closed already.

Fixes #8763.
crisbeto authored and andrewseguin committed Dec 13, 2017
1 parent bbfec2b commit 92dcd76
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/autocomplete/autocomplete-trigger.ts
Original file line number Diff line number Diff line change
@@ -193,7 +193,7 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
get panelClosingActions(): Observable<MatOptionSelectionChange> {
return merge(
this.optionSelections,
this.autocomplete._keyManager.tabOut,
this.autocomplete._keyManager.tabOut.pipe(filter(() => this._panelOpen)),
this._escapeEventStream,
this._outsideClickStream
);
17 changes: 17 additions & 0 deletions src/lib/autocomplete/autocomplete.spec.ts
Original file line number Diff line number Diff line change
@@ -1333,6 +1333,23 @@ describe('MatAutocomplete', () => {
expect(closingActionSpy).toHaveBeenCalled();
});

it('should not emit when tabbing away from a closed panel', () => {
const tabEvent = createKeyboardEvent('keydown', TAB);

input.focus();
zone.simulateZoneExit();

trigger._handleKeydown(tabEvent);

// Ensure that it emitted once while the panel was open.
expect(closingActionSpy).toHaveBeenCalledTimes(1);

trigger._handleKeydown(tabEvent);

// Ensure that it didn't emit again when tabbing out again.
expect(closingActionSpy).toHaveBeenCalledTimes(1);
});

it('should emit panel close event when selecting an option', () => {
const option = overlayContainerElement.querySelector('mat-option') as HTMLElement;

0 comments on commit 92dcd76

Please sign in to comment.