Skip to content

fix(select): handle keyboard events from inside panel #9361

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

Merged
merged 1 commit into from
Jan 23, 2018
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
3 changes: 2 additions & 1 deletion src/lib/select/select.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
(@transformPanel.done)="_onPanelDone()"
[style.transformOrigin]="_transformOrigin"
[class.mat-select-panel-done-animating]="_panelDoneAnimating"
[style.font-size.px]="_triggerFontSize">
[style.font-size.px]="_triggerFontSize"
(keydown)="_handleKeydown($event)">

<div
class="mat-select-content"
Expand Down
19 changes: 15 additions & 4 deletions src/lib/select/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,8 +759,6 @@ describe('MatSelect', () => {
expect(pane.style.minWidth).toBe('200px');
}));



it('should not attempt to open a select that does not have any options', fakeAsync(() => {
fixture.componentInstance.foods = [];
fixture.detectChanges();
Expand All @@ -771,8 +769,6 @@ describe('MatSelect', () => {
expect(fixture.componentInstance.select.panelOpen).toBe(false);
}));



it('should close the panel when tabbing out', fakeAsync(() => {
trigger.click();
fixture.detectChanges();
Expand All @@ -787,6 +783,21 @@ describe('MatSelect', () => {
expect(fixture.componentInstance.select.panelOpen).toBe(false);
}));

it('should close when tabbing out from inside the panel', fakeAsync(() => {
trigger.click();
fixture.detectChanges();
flush();

expect(fixture.componentInstance.select.panelOpen).toBe(true);

const panel = overlayContainerElement.querySelector('.mat-select-panel')!;
dispatchKeyboardEvent(panel, 'keydown', TAB);
fixture.detectChanges();
flush();

expect(fixture.componentInstance.select.panelOpen).toBe(false);
}));

it('should focus the first option when pressing HOME', fakeAsync(() => {
fixture.componentInstance.control.setValue('pizza-1');
fixture.detectChanges();
Expand Down
2 changes: 2 additions & 0 deletions src/lib/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,8 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit,
_parentFormGroup, ngControl);

if (this.ngControl) {
// Note: we provide the value accessor through here, instead of
// the `providers` to avoid running into a circular import.
this.ngControl.valueAccessor = this;
}

Expand Down