
Company News
Free Business Plan Upgrades for Open Source Maintainers
Open source maintainers are under more pressure than ever. We're raising our open source program from the Team plan to the Business plan, free.
@isoftdata/svelte-context-menu
Advanced tools
A Context/Dropdown menu component, filled with DropdownItems and DropdownCheckboxItems
pnpm i @isoftdata/svelte-context-menu
| Name | Type | Description | Default Value |
|---|---|---|---|
| id | string | The id of the context menu element. | "menu" |
| menuItemClickCloses | boolean | Whether clicking a menu item will close the menu. | true |
| placement | string | The placement of the context menu relative to the reference element. | "bottom-start" |
| aria-label | string | Accessible name for the menu. Set this or aria-labelledby so screen readers can announce what the menu is. | undefined |
| aria-labelledby | string | Id of an element that labels the menu, as an alternative to aria-label. | undefined |
This component follows the ARIA menu pattern:
ArrowUp/ArrowDown wrap around, Home/End jump to the first/last item).Escape and Tab close the menu; closing via the keyboard returns focus to whichever element opened the menu.DropdownItem renders with role="menuitem", and DropdownCheckboxItem renders with role="menuitemcheckbox" and aria-checked reflecting its checked state.aria-label or aria-labelledby, since a role="menu" element needs one to be identifiable to screen reader users.The main way you'll interact with this component is through calling the methods below. To access these methods on the component instance, you will have to use the bind:this directive on the ContextMenu in your template, and assign it to a variable, which you can then call the methods on. See Example for more details.
event - the mouse eventtargetId (optional) the id of an element. If supplied, the menu will be positioned relative to this element. Otherwise, it will be positioned relative to the cursor.<script lang="ts">
import ContextMenu from '@isoftdata/svelte-context-menu'
let cm: ContextMenu
</script>
<button
id="target"
class="btn btn-primary btn-block"
on:contextmenu={e => {
event.preventDefault()
cm.open(e, "target")
}}
>
Right Click to Open Menu
</button>
<ContextMenu bind:this={cm}>
<DropdownItem
icon="mouse"
onclick={() => alert("Dropdown Item Clicked!")}
>
Click Me!
</DropdownItem>
<div class="downdown-divider" />
<h6 class="dropdown-header">Clicked {cmClicks} time(s)</h6>
</ContextMenu>
FAQs
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Open source maintainers are under more pressure than ever. We're raising our open source program from the Team plan to the Business plan, free.

Security News
The supply chain control that delays freshly published gems now covers lockfile generation and gem vendoring in Ruby projects.

Security News
During a UK cyber test, a Mythos 5 agent used sockpuppets, social engineering, and prompt injection to try to get a maintainer to merge malware.