Skip to main content

dataKey

Description

specifies the id of the elements to show Context Menu for

Type

string

Example

Here's how you can specify ContextMenu with the default dataKey:

<script>
const resolver = id => id;
var activate;
</script>

<!--the resolver property enables the multi-area mode for the menu-->
<ContextMenu {options} {resolver} bind:handler={activate} />

<!--a menu will appear for all items with the "data-context-id" attribute -->
{#each items as item(item.id)}
<div class="item" on:click={activate} data-context-id={item.id}></div>
{/each}

The example below shows how to create ContextMenu with a custom dataKey:

<ContextMenu dataKey="dataId" />
<div data-id="1"></div>

Related article: Common context for different targets