Dropdown - Code
Basic
Dropdown with icon
Dropdown with quick actions menu
Dropdown with submenu
Open a dropdown at a pointer location (e.g. context menu)
Since 6.0.0
Use showAt(x, y) with the viewport coordinates from the contextmenu event. The dropdown can also be positioned declaratively with its anchorPosition property (see the API below).
<div id="target">Right-click here</div>
<ix-dropdown id="context-menu" role="menu">
<ix-dropdown-item label="Open"></ix-dropdown-item>
<ix-dropdown-item label="Delete"></ix-dropdown-item>
</ix-dropdown>
<script>
const target = document.querySelector('#target');
const menu = document.querySelector('#context-menu');
target.addEventListener('contextmenu', (event) => {
event.preventDefault();
menu.showAt(event.clientX, event.clientY);
});
</script>