From 46fe692d718ca3e21e75d08357c53781bfa29fa4 Mon Sep 17 00:00:00 2001 From: crisbeto Date: Tue, 20 Jun 2017 19:45:48 +0200 Subject: [PATCH] fix(select): expose focus method Exposes the `focus` method from `md-select` for consistency with `md-input-container`. Fixes #5251. --- src/lib/select/select.spec.ts | 8 ++++++++ src/lib/select/select.ts | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/lib/select/select.spec.ts b/src/lib/select/select.spec.ts index 18dd6a82bad6..7f626c4ac6bd 100644 --- a/src/lib/select/select.spec.ts +++ b/src/lib/select/select.spec.ts @@ -1688,6 +1688,14 @@ describe('MdSelect', () => { subscription.unsubscribe(); }); + it('should be able to focus the select trigger', () => { + document.body.focus(); // ensure that focus isn't on the trigger already + + fixture.componentInstance.select.focus(); + + expect(document.activeElement).toBe(select, 'Expected select element to be focused.'); + }); + }); describe('for options', () => { diff --git a/src/lib/select/select.ts b/src/lib/select/select.ts index 4f1ccce379f6..b10ba810ae65 100644 --- a/src/lib/select/select.ts +++ b/src/lib/select/select.ts @@ -397,7 +397,7 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On this._placeholderState = ''; } - this._focusHost(); + this.focus(); } } @@ -752,8 +752,8 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On } } - /** Focuses the host element when the panel closes. */ - private _focusHost(): void { + /** Focuses the select element. */ + focus(): void { this._elementRef.nativeElement.focus(); }