Skip to content

Commit cc77ef4

Browse files
crisbetotinayuangao
authored andcommitted
fix(select): don't open menu if there are no options (#2924)
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.
1 parent f29f7ab commit cc77ef4

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/lib/select/select.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@ describe('MdSelect', () => {
125125
});
126126
}));
127127

128+
it('should not attempt to open a select that does not have any options', () => {
129+
fixture.componentInstance.foods = [];
130+
fixture.detectChanges();
131+
132+
trigger.click();
133+
fixture.detectChanges();
134+
135+
expect(fixture.componentInstance.select.panelOpen).toBe(false);
136+
});
137+
128138
});
129139

130140
describe('selection logic', () => {

src/lib/select/select.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ export class MdSelect implements AfterContentInit, ControlValueAccessor, OnDestr
268268

269269
/** Opens the overlay panel. */
270270
open(): void {
271-
if (this.disabled) {
271+
if (this.disabled || !this.options.length) {
272272
return;
273273
}
274274
this._calculateOverlayPosition();

0 commit comments

Comments
 (0)