Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ContextMenu tied to DataTable always opens no matter where you right click on the page #414

Closed
fis-dan-wnuk opened this issue May 25, 2016 · 3 comments
Assignees
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@fis-dan-wnuk
Copy link

Table definition:

`<p-contextMenu #cm [model]="items" [global]="false">

    <p-dataTable *ngIf="menu" #table [value]="entries" [sortMode]="multiple" [rows]="10" [paginator]="true" [responsive]="true" [selectionMode]="getSelectionMode()"
                 (selection)="getSelection()" [contextMenu]="cm" (onContextMenuSelect)="onContextSelect($event)" (onRowClick)="onClick($event)">
        <p-column *ngIf="select" styleClass="checkbox-column">
            <template let-entry="rowData">
                <input type="checkbox" (click)="onCheckboxClick($event, entry)" [checked]="isEntrySelected(entry)" />
            </template>
        </p-column>
        <p-column *ngFor="let column of columns" [field]="column.value" [header]="column.label" [sortable]="true" [filter]="true">
            <template let-entry="rowData">
                {{getColumnValue(entry, column)}}
            </template>
        </p-column>
    </p-dataTable>`

I see the following in the ContextMenu ngAfterViewInit lifecycle method:

this.documentRightClickListener = this.renderer.listenGlobal('body', 'contextmenu', (event) => { this.show(event); event.preventDefault(); });

This seems to be registering any context menu created to always show when the body is rightclicked. Maybe when a datatable registers a context menu it can call a method that unregisters this listener? Or if global flag isn't set it doesn't create this listener at all?

@fis-dan-wnuk
Copy link
Author

On another note - the two event listeners in ContextMenu are listening on the body. Can they be changed to instead listen on the document? The reason I ask is because the application I am working on has the body centered with margin: 0 auto;. Clicking on the margin doesn't trigger a click event on the body - so essentially half the page does not cancel the right click menu.

@fis-dan-wnuk
Copy link
Author

The displaying of context menu regardless of where the right click occurs also means that when you right click on a table when there are multiple tables on the page with context menus, then one context menu is displayed for each table.

@caseylutz
Copy link

It would appear to me (after looking at the source) that the context menu appears to be only half-implemented at this time. Any updates on the status of this module? Conceptually I feel like the context-menu control should only really bind the context menu event to the parent component hosting the context menu control and then listen on the body/document for click events to dismiss the menu.

It would also be extremely helpful if an edge case could be taken into account wherein context menu controls are declared in nested components. The bottom-most component should take precedence and open up the context menu.

Example:

  • Parent Component (Contains a context menu)
  • - ngFor
  • - - Child Component (Also contains a context menu)

When the Parent Component is right-clicked outside of any of its child components, show the parent's context menu. When a child component specifically is right-clicked, show the child's context menu.

@cagataycivici cagataycivici added the Type: Bug Issue contains a bug related to a specific component. Something about the component is not working label Jul 29, 2016
@cagataycivici cagataycivici added this to the 1.0.0-beta.12 milestone Jul 29, 2016
@cagataycivici cagataycivici self-assigned this Jul 29, 2016
atretyak1985 pushed a commit to Nanitor/primeng that referenced this issue Jul 18, 2020
[NNTR-372]Software inventory view links to the Vulnerability page (old), use th…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
Development

No branches or pull requests

3 participants