Skip to content

Commit af86974

Browse files
committed
- Remove extra <md-autocomplete> blocks in example.
- Add isOpen attribute to `MdAutocomplete` component.
1 parent df808b8 commit af86974

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

src/demo-app/autocomplete/autocomplete-demo.html

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,6 @@
6666
</md-card>
6767
</div>
6868

69-
<md-autocomplete #reactiveAuto="mdAutocomplete" [displayWith]="displayFn">
70-
<md-option *ngFor="let state of reactiveStates | async" [value]="state">
71-
<span>{{ state.name }}</span>
72-
<span class="demo-secondary-text"> ({{state.code}}) </span>
73-
</md-option>
74-
</md-autocomplete>
75-
76-
<md-autocomplete #tdAuto="mdAutocomplete">
77-
<md-option *ngFor="let state of tdStates" [value]="state.name">
78-
<span>{{ state.name }}</span>
79-
</md-option>
80-
</md-autocomplete>
81-
8269
<md-autocomplete #groupedAuto="mdAutocomplete">
8370
<md-optgroup *ngFor="let group of filteredGroupedStates"
8471
[label]="'States starting with ' + group.letter">

src/lib/autocomplete/autocomplete-trigger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
180180
this._resetPlaceholder();
181181

182182
if (this._panelOpen) {
183-
this._panelOpen = false;
183+
this.autocomplete._isOpen = this._panelOpen = false;
184184

185185
// We need to trigger change detection manually, because
186186
// `fromEvent` doesn't seem to do it at the proper time.
@@ -461,7 +461,7 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
461461
}
462462

463463
this.autocomplete._setVisibility();
464-
this._panelOpen = true;
464+
this.autocomplete._isOpen = this._panelOpen = true;
465465
}
466466

467467
private _getOverlayConfig(): OverlayState {

src/lib/autocomplete/autocomplete.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,17 @@ describe('MdAutocomplete', () => {
390390
expect(inputContainer._animateAndLockPlaceholder).toHaveBeenCalled();
391391
});
392392

393+
it('should provide the open state of the panel', async(() => {
394+
expect(fixture.componentInstance.panel.isOpen).toBeFalsy(
395+
`Expected the panel to be unopened initially.`);
396+
397+
dispatchFakeEvent(input, 'focusin');
398+
fixture.detectChanges();
399+
fixture.whenStable().then(() => {
400+
expect(fixture.componentInstance.panel.isOpen).toBeTruthy(
401+
`Expected the panel to be opened on focus.`);
402+
});
403+
}));
393404
});
394405

395406
it('should have the correct text direction in RTL', () => {

src/lib/autocomplete/autocomplete.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ export class MdAutocomplete implements AfterContentInit {
5757
/** Whether the autocomplete panel should be visible, depending on option length. */
5858
showPanel = false;
5959

60+
_isOpen: boolean = false;
61+
get isOpen(): boolean {
62+
return this._isOpen && this.showPanel;
63+
}
64+
6065
/** @docs-private */
6166
@ViewChild(TemplateRef) template: TemplateRef<any>;
6267

@@ -83,6 +88,8 @@ export class MdAutocomplete implements AfterContentInit {
8388

8489
ngAfterContentInit() {
8590
this._keyManager = new ActiveDescendantKeyManager<MdOption>(this.options).withWrap();
91+
// Set the initial visibiity state.
92+
this._setVisibility();
8693
}
8794

8895
/**

0 commit comments

Comments
 (0)