From 6b4f9c86b28ff079b94f1b582670631861fc5486 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Fri, 7 Jul 2017 19:04:07 +0200 Subject: [PATCH] fix(select): disabled select being set to touched state on click (#5328) Fixes being able to set a disabled `md-select` to `touched` by clicking on it. --- src/lib/select/select.spec.ts | 11 +++++++++++ src/lib/select/select.ts | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/lib/select/select.spec.ts b/src/lib/select/select.spec.ts index 98d1e77d898..a8a7726c435 100644 --- a/src/lib/select/select.spec.ts +++ b/src/lib/select/select.spec.ts @@ -635,6 +635,17 @@ describe('MdSelect', () => { .toEqual(true, `Expected the control to be touched as soon as focus left the select.`); }); + it('should not set touched when a disabled select is touched', () => { + expect(fixture.componentInstance.control.touched) + .toBe(false, 'Expected the control to start off as untouched.'); + + fixture.componentInstance.control.disable(); + dispatchFakeEvent(trigger, 'blur'); + + expect(fixture.componentInstance.control.touched) + .toBe(false, 'Expected the control to stay untouched.'); + }); + it('should set the control to dirty when the select\'s value changes in the DOM', () => { expect(fixture.componentInstance.control.dirty) .toEqual(false, `Expected control to start out pristine.`); diff --git a/src/lib/select/select.ts b/src/lib/select/select.ts index a0d3f03d70a..493f5522b1a 100644 --- a/src/lib/select/select.ts +++ b/src/lib/select/select.ts @@ -534,7 +534,7 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On * "blur" to the panel when it opens, causing a false positive. */ _onBlur() { - if (!this.panelOpen) { + if (!this.disabled && !this.panelOpen) { this._onTouched(); } }