From 8bf54629abd4a7e4c97691bb12656d547193c6f5 Mon Sep 17 00:00:00 2001 From: crisbeto Date: Fri, 3 Feb 2017 21:17:02 +0100 Subject: [PATCH] fix(select): don't open menu if there are no options Currently the select will attempt to show it's menu when there are no options, which ends up looking like a slight box shadow that shows up above it. This change prevents the menu from opening at all if it's empty. --- src/lib/select/select.spec.ts | 10 ++++++++++ src/lib/select/select.ts | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/lib/select/select.spec.ts b/src/lib/select/select.spec.ts index 5f57794bdd80..7f3e6ad47a6f 100644 --- a/src/lib/select/select.spec.ts +++ b/src/lib/select/select.spec.ts @@ -117,6 +117,16 @@ describe('MdSelect', () => { }); })); + it('should not attempt to open a select that does not have any options', () => { + fixture.componentInstance.foods = []; + fixture.detectChanges(); + + trigger.click(); + fixture.detectChanges(); + + expect(fixture.componentInstance.select.panelOpen).toBe(false); + }); + }); describe('selection logic', () => { diff --git a/src/lib/select/select.ts b/src/lib/select/select.ts index 1a3dabfd5fc6..872fd79079a8 100644 --- a/src/lib/select/select.ts +++ b/src/lib/select/select.ts @@ -266,7 +266,7 @@ export class MdSelect implements AfterContentInit, ControlValueAccessor, OnDestr /** Opens the overlay panel. */ open(): void { - if (this.disabled) { + if (this.disabled || !this.options.length) { return; } this._calculateOverlayPosition();