Skip to content

Commit 6b4f9c8

Browse files
crisbetommalerba
authored andcommitted
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.
1 parent a5a8ff2 commit 6b4f9c8

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/lib/select/select.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,17 @@ describe('MdSelect', () => {
635635
.toEqual(true, `Expected the control to be touched as soon as focus left the select.`);
636636
});
637637

638+
it('should not set touched when a disabled select is touched', () => {
639+
expect(fixture.componentInstance.control.touched)
640+
.toBe(false, 'Expected the control to start off as untouched.');
641+
642+
fixture.componentInstance.control.disable();
643+
dispatchFakeEvent(trigger, 'blur');
644+
645+
expect(fixture.componentInstance.control.touched)
646+
.toBe(false, 'Expected the control to stay untouched.');
647+
});
648+
638649
it('should set the control to dirty when the select\'s value changes in the DOM', () => {
639650
expect(fixture.componentInstance.control.dirty)
640651
.toEqual(false, `Expected control to start out pristine.`);

src/lib/select/select.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
534534
* "blur" to the panel when it opens, causing a false positive.
535535
*/
536536
_onBlur() {
537-
if (!this.panelOpen) {
537+
if (!this.disabled && !this.panelOpen) {
538538
this._onTouched();
539539
}
540540
}

0 commit comments

Comments
 (0)