mirror of
https://github.com/johannesjo/super-productivity.git
synced 2026-07-17 16:37:43 +00:00
feat: improve context menu and limit to certain containers only
This commit is contained in:
parent
90e27194fa
commit
9af991080c
2 changed files with 25 additions and 0 deletions
|
|
@ -110,6 +110,9 @@
|
|||
<context-menu
|
||||
[contextMenu]="backgroundContextMenu"
|
||||
[rightClickTriggerEl]="routeWrapper.nativeElement"
|
||||
[allowedSelectors]="
|
||||
'.route-wrapper, .today, .task-list-wrapper, .page-wrapper, .route-wrapper > *, .search-results'
|
||||
"
|
||||
></context-menu>
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ export class ContextMenuComponent implements OnInit {
|
|||
leftClickTriggerEl = input<HTMLElement | MatMenuItem | MatIconButton | undefined>();
|
||||
rightClickTriggerEl = input.required<HTMLElement | MatMenuItem | MatIconButton>();
|
||||
contextMenu = input.required<TemplateRef<any>>();
|
||||
allowedSelectors = input<string>('');
|
||||
|
||||
readonly contextMenuTriggerEl = viewChild.required('contextMenuTriggerEl', {
|
||||
read: MatMenuTrigger,
|
||||
|
|
@ -57,6 +58,27 @@ export class ContextMenuComponent implements OnInit {
|
|||
}
|
||||
|
||||
private openContextMenu(event: TouchEvent | MouseEvent): void {
|
||||
// If allowedSelectors is provided, check if the target matches any of the selectors
|
||||
const allowedSelectors = this.allowedSelectors();
|
||||
if (allowedSelectors) {
|
||||
const target = event.target as HTMLElement;
|
||||
const selectors = allowedSelectors.split(',').map((s) => s.trim());
|
||||
|
||||
// Check if the target matches any of the allowed selectors
|
||||
let isAllowed = false;
|
||||
for (const selector of selectors) {
|
||||
if (target.matches(selector)) {
|
||||
isAllowed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If target doesn't match any selector, don't open the menu
|
||||
if (!isAllowed) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
this.contextMenuPosition.x =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue