Skip to content

Commit

Permalink
fix(select): expose focus method (#5255)
Browse files Browse the repository at this point in the history
Exposes the `focus` method from `md-select` for consistency with `md-input-container`.

Fixes #5251.
  • Loading branch information
crisbeto authored and jelbourn committed Jun 23, 2017
1 parent c81e608 commit 7b2d4ae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/lib/select/select.spec.ts
Expand Up @@ -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', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/select/select.ts
Expand Up @@ -398,7 +398,7 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
this._placeholderState = '';
}

this._focusHost();
this.focus();
}
}

Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit 7b2d4ae

Please sign in to comment.