HextaUI

Context menu: Render as another element

Use render to make the trigger any element, such as a figure, or to turn an item into a link.

Trigger rendered as a figure
import { IconDownload, IconLink } from "@tabler/icons-react"

import {
  ContextMenu,
  ContextMenuContent,
  ContextMenuItem,
  ContextMenuTrigger,
} from "@/components/ui/context-menu"

export function ContextMenuRender() {
  return (
    <ContextMenu>
      <ContextMenuTrigger
        render={<figure />}
        className="flex w-full max-w-xs flex-col gap-2 rounded-xl border p-3"
      >
        <div className="h-28 rounded-lg bg-muted" />
        <figcaption className="text-sm text-muted-foreground">
          Trigger rendered as a figure
        </figcaption>
      </ContextMenuTrigger>
      <ContextMenuContent>
        <ContextMenuItem>
          <IconDownload />
          Save image
        </ContextMenuItem>
        <ContextMenuItem render={<a href="#render-as-another-element" />}>
          <IconLink />
          Link item
        </ContextMenuItem>
      </ContextMenuContent>
    </ContextMenu>
  )
}

This adds the example as components/examples/context-menu/render.tsx, together with the Context menu component and the HextaUI theme tokens it needs.

pnpm dlx shadcn@latest add https://hextaui.com/r/context-menu-render.json

To add only the component, follow the Context menu installation.

Props in this example

The Context menu props this example sets, from the API reference.

PropTypeDefault
render
ReactElement | (props, state) => ReactElement<div>
PropTypeDefault
render
ReactElement | (props, state) => ReactElement<div>

Every prop is in the Context menu API reference.

See them all, with keyboard support and accessibility notes, on the Context menu page.