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

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

Fixes #8763.
  • Loading branch information
crisbeto committed Dec 2, 2017
1 parent 5210b3e commit 6267ea5
Show file tree
Hide file tree
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
Expand Up @@ -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
);
Expand Down
17 changes: 17 additions & 0 deletions src/lib/autocomplete/autocomplete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1370,6 +1370,23 @@ describe('MatAutocomplete', () => {
});
}));

it('should not emit if tabbing away from a closed pabel', async(() => {
const tabEvent = createKeyboardEvent('keydown', TAB);
input.focus();

fixture.whenStable().then(() => {
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', async(() => {
fixture.whenStable().then(() => {
const option = overlayContainerElement.querySelector('mat-option') as HTMLElement;
Expand Down

0 comments on commit 6267ea5

Please sign in to comment.