Components/ContextMenu
Universal Component

ContextMenu

Right-click and controlled floating menu built on Floating UI.

This page was migrated by AI, please review carefully

Migration is complete, but please validate against source code and manual review.

ContextMenu

Right-click and controlled floating menu built on Floating UI. It supports uncontrolled context-menu triggers and controlled coordinates through v-model, x, and y.

Basic Usage

ContextMenu

Demo will load when visible.
<script setup lang="ts">
import { ref } from 'vue'

const controlledOpen = ref(false)
const x = ref(0)
const y = ref(0)

function openAtCenter() {
  x.value = Math.round(window.innerWidth * 0.5)
  y.value = Math.round(window.innerHeight * 0.38)
  controlledOpen.value = true
}
</script>

<template>
  <div style="display: grid; gap: 12px; width: 520px;">
    <div style="display: flex; gap: 8px; align-items: center;">
      <TxButton type="primary" @click="openAtCenter">
        Open controlled menu
      </TxButton>
      <TxButton @click="controlledOpen = false">
        Close
      </TxButton>
    </div>

    <TxContextMenu
      v-model="controlledOpen"
      :x="x"
      :y="y"
      @open="() => {}"
    >
      <template #menu>
        <TxContextMenuItem @select="() => {}">
          Copy
        </TxContextMenuItem>
        <TxContextMenuItem @select="() => {}">
          Paste
        </TxContextMenuItem>
        <TxContextMenuItem danger @select="() => {}">
          Delete
        </TxContextMenuItem>
      </template>
    </TxContextMenu>

    <TxContextMenu>
      <template #trigger>
        <div
          style="
            width: 100%;
            padding: 24px;
            border: 1px dashed var(--tx-border-color);
            border-radius: 12px;
            user-select: none;
          "
        >
          Right click here (uncontrolled)
        </div>
      </template>

      <template #menu>
        <TxContextMenuItem @select="() => {}">
          Refresh
        </TxContextMenuItem>
        <TxContextMenuItem @select="() => {}">
          Rename
        </TxContextMenuItem>
        <TxContextMenuItem danger @select="() => {}">
          Delete
        </TxContextMenuItem>
      </template>
    </TxContextMenu>
  </div>
</template>

API

TxContextMenu Props

PropTypeDefaultDescription
modelValueboolean | undefinedundefinedControlled open state; leave undefined for internal uncontrolled state.
xnumber0Controlled menu anchor X coordinate.
ynumber0Controlled menu anchor Y coordinate.
widthnumber220Menu panel width in pixels.
closeOnEscbooleantrueCloses the menu when Escape is pressed.
closeOnClickOutsidebooleantrueCloses the menu on pointer events outside the trigger and menu.

TxContextMenu Events

EventParamsDescription
open{ x: number; y: number }Emitted when the menu opens with the active anchor coordinates.
close-Emitted when the menu closes.

TxContextMenuItem Props

PropTypeDefaultDescription
disabledbooleanfalseDisables selection and item clickability.
dangerbooleanfalseApplies danger styling to the item label.

TxContextMenuItem Events

EventParamsDescription
select-Emitted when an enabled item is selected; the parent context menu then closes.