Skip to content

Commit 7b2d4ae

Browse files
crisbetojelbourn
authored andcommitted
fix(select): expose focus method (#5255)
Exposes the `focus` method from `md-select` for consistency with `md-input-container`. Fixes #5251.
1 parent c81e608 commit 7b2d4ae

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/lib/select/select.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,6 +1701,14 @@ describe('MdSelect', () => {
17011701
subscription.unsubscribe();
17021702
});
17031703

1704+
it('should be able to focus the select trigger', () => {
1705+
document.body.focus(); // ensure that focus isn't on the trigger already
1706+
1707+
fixture.componentInstance.select.focus();
1708+
1709+
expect(document.activeElement).toBe(select, 'Expected select element to be focused.');
1710+
});
1711+
17041712
});
17051713

17061714
describe('for options', () => {

src/lib/select/select.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
398398
this._placeholderState = '';
399399
}
400400

401-
this._focusHost();
401+
this.focus();
402402
}
403403
}
404404

@@ -753,8 +753,8 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
753753
}
754754
}
755755

756-
/** Focuses the host element when the panel closes. */
757-
private _focusHost(): void {
756+
/** Focuses the select element. */
757+
focus(): void {
758758
this._elementRef.nativeElement.focus();
759759
}
760760

0 commit comments

Comments
 (0)