Skip to content

Commit

Permalink
fix(autocomplete): not showing panel on first focus in certain cases (#…
Browse files Browse the repository at this point in the history
…3775)

Fixes a case where the first time an autocomplete is focused by clicking within its input container (note not directly on the input), the panel is invisible, because its `showPanel` flag hasn't been set yet.

Relates to #3722.
  • Loading branch information
crisbeto authored and jelbourn committed Mar 25, 2017
1 parent 23d18a8 commit 75996b5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/lib/autocomplete/autocomplete-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
this._subscribeToClosingActions();
}

this._panelOpen = true;
this.autocomplete._setVisibility();
this._floatPlaceholder();
this._panelOpen = true;
}

/** Closes the autocomplete suggestion panel. */
Expand Down
15 changes: 15 additions & 0 deletions src/lib/autocomplete/autocomplete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,21 @@ describe('MdAutocomplete', () => {
});
}));

it('should show the panel when the first open is after the initial zone stabilization',
async(() => {
// Note that we're running outside the Angular zone, in order to be able
// to test properly without the subscription from `_subscribeToClosingActions`
// giving us a false positive.
fixture.ngZone.runOutsideAngular(() => {
fixture.componentInstance.trigger.openPanel();

Promise.resolve().then(() => {
expect(fixture.componentInstance.panel.showPanel)
.toBe(true, `Expected panel to be visible.`);
});
});
}));

it('should close the panel when blurred', async(() => {
dispatchFakeEvent(input, 'focus');
fixture.detectChanges();
Expand Down

0 comments on commit 75996b5

Please sign in to comment.