Open ContextMenu relative to button with left-click

Hi,

I want to open the ContextMenu relative to the position of a button on page with the left mouse button click. I tried your example 'Open and close ContextMenu in Angular ContextMenu component', but the menu is opening at the co-ordinates relative to the browser window, and not where the button is on page.

<div class="form-input">
                            <label>Open Date</label>
                            <ejs-contextmenu id='contextmenu' target="#target" [items]='menuItems'></ejs-contextmenu>
                            <button ejs-button id="target" (click)="btnClick()">Open ContextMenu</button>
                        </div>


btnClick() {
        let contextmenuObj: ContextMenu = getInstance(document.getElementById("contextmenu"), ContextMenu) as ContextMenu;
        contextmenuObj.open(30, 0);
    }

    public menuItems: MenuItemModel[] = [
        {
            text: 'Cut'
        },
        {
            text: 'Copy'
        },
        {
            text: 'Paste'
        }
    ]; 

3 Replies 1 reply marked as answer

MV Madhan Venkateshan Syncfusion Team July 17, 2020 06:56 AM UTC

Hi Glen Alexander, 
 
Good day to you. 
 
You can use ‘open’ method of context menu and set the position based on button position. Please refer the below sample link. And also we would let you know that we have Dropdown button component similar to your use case, please refer the sample browser link and documentation link. 
 
 
 
 
Regards, 
Madhan V 



GA Glen Alexander July 19, 2020 11:34 PM UTC

Hi,

Thanks for this. is there something similar that can be done for positioning a Dialog? So if I wanted to open a dialog directly underneath a button?


SD Saranya Dhayalan Syncfusion Team July 20, 2020 11:08 AM UTC

Hi Glen Alexander,  
 
Most welcome 
 
We have checked your reported query, you can achieve this by using the position property. Please find the below code snippet: 
 
<div id="target" style="min-height: 175px;"> 
    <button class="e-btn" (click)="btnClick($event)">Open ContextMenu</button> 
    <div> 
        <ejs-dialog id='dialog' #ejDialog header='Dialog' showCloseIcon='true' content='This is a dialog with header' 
                    target='#target' [position]='position1' width='250px'> 
            <div style='padding:18px;padding-top:0px;'> 
            </div> 
        </ejs-dialog> 
    </div> 
 
For your convenience, we have prepared a sample link. Please find the below sample link 
 
 
Please check the above sample and get back to us if you need further assistance on this. 
 
Regards, 
Saranya D 


Marked as answer
Loader.
Up arrow icon