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

Attach ContextMenu to any Element #358

Closed
sdmoralesma opened this issue May 13, 2016 · 1 comment
Closed

Attach ContextMenu to any Element #358

sdmoralesma opened this issue May 13, 2016 · 1 comment
Assignees
Labels
Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add
Milestone

Comments

@sdmoralesma
Copy link
Contributor

sdmoralesma commented May 13, 2016

I followed the bug: #222 and locally I tested primeng beta5 (+ angular-rc1) and although the contextmenu works globally, when I try to use it in different components is not being displayed and Not throwing any exception, example:

I want to have different context menus, one for a p-toolbar and other for a div, I tried doing this:
for p-toolbar:

<p-toolbar>
    <p-contextMenu [global]="false">
        <ul>
            <li>
                <a data-icon="fa-file-o">
                    <span>File</span>
                </a>
                <ul>
                    <li>
                        <a>
                            <span>Open</span>
                        </a>
                    </li>
                    <li>
                        <a>
                            <span>Quit</span>
                        </a>
                    </li>
                </ul>
            </li>
        </ul>
        <div class="ui-toolbar-group-right">
            <button pButton type="button" data-icon="fa-plus"></button>
            <button pButton type="button" data-icon="fa-close"></button>
        </div>
    </p-contextMenu>
</p-toolbar>

for div:

<div style="margin-bottom: 10px;">
    <p-contextMenu [global]="false">
        <ul>
            <li>
                <a data-icon="fa-file-o">
                    <span>File</span>
                </a>
            </li>
        </ul>
    </p-contextMenu>
    <p-tree [value]="files" selectionMode="single" [(selection)]="selectedFile"
            (onNodeSelect)="myfunction()" (onNodeUnselect)="myotherfunction($event)"></p-tree>
</div>

But is not displaying any context menu. Am I doing something wrong?

@fischey
Copy link

fischey commented Dec 18, 2016

I had the same problem.
The "problem" is the missing eventhandler which opens the contextmenu. In "local mode"([global]=false) you have to register an eventhandler on your own.
In global mode there is a global eventhandler registered during the onInit-method of the contextmenu which causes the contextmenu to open. See the Code ContextMenu-OnInit-method

If you add a handler to a component you can open the contextMenu via the exposed methods of the contextMenu class(show/hide + toggle).

For example you can do the following:

<p-contextMenu #contextMenu [model]="[{label:'Test'}]"></p-contextMenu>
<button (click)="contextMenu.show($event);$event.stopPropagation()">Test:{{contextMenu.visible}}</button>

The button will open the contextMenu with one entry. Beware of the $event.stopPropagation() part. If you drop this part, you will never see the contextMenu because the click event from the button will be propageted(forwarded) to the browser and the same click event which opens the menu will close it directly, see the clickHandler in the contextMenu class

I hope this helps you a little bit.

Best regards.

@cagataycivici cagataycivici changed the title [Bug] contextmenu not working on elements Attach ContextMenu to any Element Mar 9, 2017
@cagataycivici cagataycivici self-assigned this Mar 9, 2017
@cagataycivici cagataycivici added the Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add label Mar 9, 2017
@cagataycivici cagataycivici added this to the 4.0.RC1 milestone Mar 9, 2017
atretyak1985 pushed a commit to Nanitor/primeng that referenced this issue Jul 18, 2020
[NNTR-287]Changes to individual \device details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add
Projects
None yet
Development

No branches or pull requests

3 participants