Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(select): expose focus method #5255

Merged
merged 1 commit into from
Jun 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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