Skip to content

Commit

Permalink
fix(select): expose focus method
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 angular#5251.
  • Loading branch information
crisbeto committed Jun 20, 2017
1 parent a2a25be commit 46fe692
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
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
this._placeholderState = '';
}

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

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

Expand Down

0 comments on commit 46fe692

Please sign in to comment.