From 7b2d4ae601adf15f6313a32accf8feb7e329c8d3 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Fri, 23 Jun 2017 20:17:21 +0200 Subject: [PATCH] fix(select): expose focus method (#5255) 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 14dc27354653..52da5e0bbd5f 100644 --- a/src/lib/select/select.spec.ts +++ b/src/lib/select/select.spec.ts @@ -1701,6 +1701,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 d6e4ab223fe8..30a3bacffede 100644 --- a/src/lib/select/select.ts +++ b/src/lib/select/select.ts @@ -398,7 +398,7 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On this._placeholderState = ''; } - this._focusHost(); + this.focus(); } } @@ -753,8 +753,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(); }