Skip to content

Commit

Permalink
fix(select): handle keyboard events from inside panel (#9361)
Browse files Browse the repository at this point in the history
After the switch to using `aria-describedby` for managing the highlights in `mat-select`, all of the keyboard handling was moved to the select trigger, however this doesn't account for the cases where focus makes it inside the panel (e.g. when toggling options in `multiple` mode).
  • Loading branch information
crisbeto authored and jelbourn committed Jan 29, 2018
1 parent f6a59cd commit 0d233b2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
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

0 comments on commit 0d233b2

Please sign in to comment.