Skip to content

Commit

Permalink
fix: Prevent several instances of a sub menu when opening with the mouse
Browse files Browse the repository at this point in the history
  • Loading branch information
sroucheray committed Mar 8, 2024
1 parent f180b4f commit b3d1b4e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Fix

- Prevent several instances of a sub menu when opening with the mouse

## [17.0.0] - 2023-11-10

### BREAKING CHANGES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -903,4 +903,49 @@ describe('Component: ContextMenuContentComponent', () => {
).not.toHaveBeenCalled();
});
});

describe('#openSubMenu', () => {
beforeEach(() => {
configureTestingModule();
component.contextMenuContentItems = new QueryList();
});

it('should show subMenu', () => {
const subMenu =
TestBed.createComponent(ContextMenuComponent).componentInstance;
const event = new MouseEvent('click');

spyOn(subMenu, 'show');
component.openSubMenu(subMenu, event);

expect(subMenu.show).toHaveBeenCalledWith({
anchoredTo: 'position',
x: 0,
y: 0,
value: undefined,
});
});

it('should not show subMenu if already opened', () => {
const subMenu =
TestBed.createComponent(ContextMenuComponent).componentInstance;
const event = new MouseEvent('click');
spyOnProperty(subMenu, 'isOpen', 'get').and.returnValue(true);
spyOn(subMenu, 'show');
component.openSubMenu(subMenu, event);

expect(subMenu.show).not.toHaveBeenCalled();
});

it('should not throw if subMenu does not exist', () => {
const subMenu =
TestBed.createComponent(ContextMenuComponent).componentInstance;
const event = new MouseEvent('click');

spyOn(subMenu, 'show');
expect(() => {
component.openSubMenu(undefined, event);
}).not.toThrow();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export class ContextMenuContentComponent<T>
subMenu: ContextMenuComponent<T> | undefined,
event: MouseEvent | KeyboardEvent
): void {
if (!subMenu) {
if (!subMenu || subMenu.isOpen) {
return;
}

Expand Down

0 comments on commit b3d1b4e

Please sign in to comment.