Skip to content
Open
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
6 changes: 6 additions & 0 deletions src/cdk/menu/menu-aim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ export class TargetMenuAim implements MenuAim, OnDestroy {

ngOnDestroy() {
this._cleanupMousemove?.();

if (this._timeoutId !== null) {
clearTimeout(this._timeoutId);
this._timeoutId = null;
}

this._destroyed.next();
this._destroyed.complete();
}
Expand Down
33 changes: 27 additions & 6 deletions src/cdk/menu/menu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,6 @@ describe('Menu', () => {
});

describe('menu aim', () => {
// TODO(crisbeto): update the component to clear timeouts on destroy.
// Give some time for timeouts to be cleaned up.
afterEach(async () => {
await wait(350);
});

/** A coordinate in the browser window */
type Point = {x: number; y: number};

Expand Down Expand Up @@ -276,6 +270,33 @@ describe('Menu', () => {
expect(nativeMenus[1].id).toBe('share_menu');
});

it('should not toggle a menu if the menu aim is destroyed while waiting', async () => {
openFileMenu();
openMenuOnHover(nativeEditTrigger!);
const editPosition = nativeEditTrigger!.getBoundingClientRect();
const sharePosition = nativeShareTrigger!.getBoundingClientRect();

// Move towards the edit submenu and stop on the share trigger so that
// the menu aim delays opening the share menu.
await hover(
{
x: editPosition.x + editPosition.width / 2,
y: editPosition.y + editPosition.height - 10,
},
{
x: sharePosition.x + sharePosition.width - 10,
y: sharePosition.y + sharePosition.height - 10,
},
nativeMenus[0],
0,
);

fixture.destroy();
await wait(350);

expect(document.querySelector('#share_menu')).toBeNull();
});

it('should not close the edit submenu when hovering into its items in time', async () => {
openFileMenu();
openMenuOnHover(nativeEditTrigger!);
Expand Down
Loading