fix(menu): closing parent overlay when pressing escape (#13442)

This commit is contained in:
Kristiyan Kostadinov
2018-10-19 17:04:45 +02:00
committed by Joey Perrott
parent cfeab79575
commit a7df1d0a3b
3 changed files with 5 additions and 3 deletions
-1
View File
@@ -262,7 +262,6 @@ export class MatMenu implements AfterContentInit, MatMenuPanel<MatMenuItem>, OnI
switch (keyCode) {
case ESCAPE:
this.closed.emit('keydown');
event.stopPropagation();
break;
case LEFT_ARROW:
if (this.parentMenu && this.direction === 'ltr') {
+5
View File
@@ -350,6 +350,11 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
const config = this._getOverlayConfig();
this._subscribeToPositions(config.positionStrategy as FlexibleConnectedPositionStrategy);
this._overlayRef = this._overlay.create(config);
// Consume the `keydownEvents` in order to prevent them from going to another overlay.
// Ideally we'd also have our keyboard event logic in here, however doing so will
// break anybody that may have implemented the `MatMenuPanel` themselves.
this._overlayRef.keydownEvents().subscribe();
}
return this._overlayRef;
-2
View File
@@ -254,14 +254,12 @@ describe('MatMenu', () => {
const panel = overlayContainerElement.querySelector('.mat-menu-panel')!;
const event = createKeyboardEvent('keydown', ESCAPE);
const stopPropagationSpy = spyOn(event, 'stopPropagation').and.callThrough();
dispatchEvent(panel, event);
fixture.detectChanges();
tick(500);
expect(overlayContainerElement.textContent).toBe('');
expect(stopPropagationSpy).toHaveBeenCalled();
}));
it('should open a custom menu', () => {