Context Menu

A menu that can be triggered by a right click or a long press.
Enabled
Hide
Wrap with stack
⌘G
Create component
View code
Copy
⌘C
Delete
⌘D
Properties
No properties to configure
Example
Source Code
Installation
"use client";

import React from "react";
import { ContextMenu } from "@/subframe/components/ContextMenu";
import { Badge } from "@/subframe/components/Badge";
import * as SubframeCore from "@subframe/core";
import { Button } from "@/subframe/components/Button";

function ContextMenuExample() {
  return (
    <SubframeCore.ContextMenu.Root>
      <SubframeCore.ContextMenu.Trigger asChild={true}>
        <Button onClick={(event: React.MouseEvent<HTMLButtonElement>) => {}}>
          Context Menu Button
        </Button>
      </SubframeCore.ContextMenu.Trigger>
      <SubframeCore.ContextMenu.Portal>
        <SubframeCore.ContextMenu.Content
          side="bottom"
          align="start"
          sideOffset={4}
          asChild={true}
        >
          <ContextMenu>
            <ContextMenu.ContextItem icon="FeatherCheck">
              Enabled
            </ContextMenu.ContextItem>
            <ContextMenu.ContextItem icon="FeatherEyeOff">
              Hide
            </ContextMenu.ContextItem>
            <ContextMenu.ContextItem
              icon={null}
              rightSlot={<Badge variant="neutral">⌘G</Badge>}
            >
              Wrap with stack
            </ContextMenu.ContextItem>
            <ContextMenu.ContextDivider />
            <ContextMenu.ContextItem icon="FeatherComponent">
              Create component
            </ContextMenu.ContextItem>
            <ContextMenu.ContextItem icon={null}>
              View code
            </ContextMenu.ContextItem>
            <ContextMenu.ContextItem
              icon="FeatherCopy"
              rightSlot={<Badge variant="neutral">⌘C</Badge>}
            >
              Copy
            </ContextMenu.ContextItem>
            <ContextMenu.ContextItem
              icon="FeatherTrash"
              rightSlot={<Badge variant="neutral">⌘D</Badge>}
            >
              Delete
            </ContextMenu.ContextItem>
          </ContextMenu>
        </SubframeCore.ContextMenu.Content>
      </SubframeCore.ContextMenu.Portal>
    </SubframeCore.ContextMenu.Root>
  );
}

export default ContextMenuExample;

Props

Context Menu
Context Divider
Context Item
Prop
Type
Default
Additional info
children
React.ReactNode

Examples

Basics

Wrap your content with SubframeCore.ContextMenu to show the context menu. It has the same API as Radix UI's ContextMenu component.