Skip to content

Commit 75996b5

Browse files
crisbetojelbourn
authored andcommitted
fix(autocomplete): not showing panel on first focus in certain cases (#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.
1 parent 23d18a8 commit 75996b5

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/lib/autocomplete/autocomplete-trigger.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,9 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
131131
this._subscribeToClosingActions();
132132
}
133133

134-
this._panelOpen = true;
134+
this.autocomplete._setVisibility();
135135
this._floatPlaceholder();
136+
this._panelOpen = true;
136137
}
137138

138139
/** Closes the autocomplete suggestion panel. */

src/lib/autocomplete/autocomplete.spec.ts

+15
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,21 @@ describe('MdAutocomplete', () => {
101101
});
102102
}));
103103

104+
it('should show the panel when the first open is after the initial zone stabilization',
105+
async(() => {
106+
// Note that we're running outside the Angular zone, in order to be able
107+
// to test properly without the subscription from `_subscribeToClosingActions`
108+
// giving us a false positive.
109+
fixture.ngZone.runOutsideAngular(() => {
110+
fixture.componentInstance.trigger.openPanel();
111+
112+
Promise.resolve().then(() => {
113+
expect(fixture.componentInstance.panel.showPanel)
114+
.toBe(true, `Expected panel to be visible.`);
115+
});
116+
});
117+
}));
118+
104119
it('should close the panel when blurred', async(() => {
105120
dispatchFakeEvent(input, 'focus');
106121
fixture.detectChanges();

0 commit comments

Comments
 (0)