Skip to content

Commit 0c39219

Browse files
authored
revert #8654 (#8865)
1 parent 426f11f commit 0c39219

File tree

3 files changed

+8
-44
lines changed

3 files changed

+8
-44
lines changed

src/lib/menu/menu-directive.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ export class MatMenu implements AfterContentInit, MatMenuPanel, OnDestroy {
188188

189189
ngOnDestroy() {
190190
this._tabSubscription.unsubscribe();
191+
this.closed.emit();
191192
this.closed.complete();
192193
}
193194

src/lib/menu/menu-trigger.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,9 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
193193
openMenu(): void {
194194
if (!this._menuOpen) {
195195
this._createOverlay().attach(this._portal);
196-
this._closeSubscription = this._menuClosingActions().subscribe(() => this.closeMenu());
196+
this._closeSubscription = this._menuClosingActions().subscribe(() => {
197+
this.menu.close.emit();
198+
});
197199
this._initMenu();
198200

199201
if (this.menu instanceof MatMenu) {
@@ -216,8 +218,8 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
216218
private _destroyMenu() {
217219
if (this._overlayRef && this.menuOpen) {
218220
this._resetMenu();
219-
this._closeSubscription.unsubscribe();
220221
this._overlayRef.detach();
222+
this._closeSubscription.unsubscribe();
221223

222224
if (this.menu instanceof MatMenu) {
223225
this.menu._resetAnimation();
@@ -398,14 +400,13 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
398400
/** Returns a stream that emits whenever an action that should close the menu occurs. */
399401
private _menuClosingActions() {
400402
const backdrop = this._overlayRef!.backdropClick();
401-
const detachments = this._overlayRef!.detachments();
402403
const parentClose = this._parentMenu ? this._parentMenu.close : observableOf();
403404
const hover = this._parentMenu ? this._parentMenu._hovered().pipe(
404405
filter(active => active !== this._menuItemInstance),
405406
filter(() => this._menuOpen)
406407
) : observableOf();
407408

408-
return merge(backdrop, parentClose, hover, detachments);
409+
return merge(backdrop, parentClose, hover);
409410
}
410411

411412
/** Handles mouse presses on the trigger. */

src/lib/menu/menu.spec.ts

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
QueryList,
1414
} from '@angular/core';
1515
import {Direction, Directionality} from '@angular/cdk/bidi';
16-
import {OverlayContainer, Overlay} from '@angular/cdk/overlay';
16+
import {OverlayContainer} from '@angular/cdk/overlay';
1717
import {ESCAPE, LEFT_ARROW, RIGHT_ARROW} from '@angular/cdk/keycodes';
1818
import {
1919
MAT_MENU_DEFAULT_OPTIONS,
@@ -25,7 +25,7 @@ import {
2525
MenuPositionY,
2626
MatMenuItem,
2727
} from './index';
28-
import {MENU_PANEL_TOP_PADDING, MAT_MENU_SCROLL_STRATEGY} from './menu-trigger';
28+
import {MENU_PANEL_TOP_PADDING} from './menu-trigger';
2929
import {MatRipple} from '@angular/material/core';
3030
import {
3131
dispatchKeyboardEvent,
@@ -35,8 +35,6 @@ import {
3535
createMouseEvent,
3636
dispatchFakeEvent,
3737
} from '@angular/cdk/testing';
38-
import {Subject} from 'rxjs/Subject';
39-
import {ScrollDispatcher} from '@angular/cdk/scrolling';
4038

4139

4240
describe('MatMenu', () => {
@@ -244,42 +242,6 @@ describe('MatMenu', () => {
244242
expect(document.activeElement).toBe(panel, 'Expected the panel to be focused.');
245243
});
246244

247-
it('should close the menu when using the CloseScrollStrategy', fakeAsync(() => {
248-
const scrolledSubject = new Subject();
249-
250-
TestBed
251-
.resetTestingModule()
252-
.configureTestingModule({
253-
imports: [MatMenuModule, NoopAnimationsModule],
254-
declarations: [SimpleMenu, FakeIcon],
255-
providers: [
256-
{
257-
provide: ScrollDispatcher,
258-
useFactory: () => ({scrolled: () => scrolledSubject})
259-
},
260-
{
261-
provide: MAT_MENU_SCROLL_STRATEGY,
262-
deps: [Overlay],
263-
useFactory: (overlay: Overlay) => () => overlay.scrollStrategies.close()
264-
}
265-
]
266-
});
267-
268-
const fixture = TestBed.createComponent(SimpleMenu);
269-
const trigger = fixture.componentInstance.trigger;
270-
271-
fixture.detectChanges();
272-
trigger.openMenu();
273-
fixture.detectChanges();
274-
275-
expect(trigger.menuOpen).toBe(true);
276-
277-
scrolledSubject.next();
278-
tick(500);
279-
280-
expect(trigger.menuOpen).toBe(false);
281-
}));
282-
283245
describe('positions', () => {
284246
let fixture: ComponentFixture<PositionedMenu>;
285247
let panel: HTMLElement;

0 commit comments

Comments
 (0)