Tesserae

ContextMenu

Description

The ContextMenu component displays a contextual pop-up menu that appears relative to a target element or specific screen coordinates. It is designed for surfacing a list of commands or options in response to user interactions such as clicks or right-clicks. This component is part of the Surfaces group and supports features like submenus, dividers, headers, and disabled items. It is ideal when you need to present contextual actions without cluttering the main UI.

Usage

The ContextMenu is instantiated using the static helper method from the Tesserae.UI class. Items can be added via the fluent API using the Items method, and the menu is shown by calling ShowFor (with either an IComponent or an HTMLElement) or ShowAt (with explicit x, y coordinates). When the menu is active, it manages focus and supports keyboard navigation (up/down arrows to navigate, Esc to dismiss).

Below is a minimalistic sample demonstrating how to create and show a basic ContextMenu:

Public Properties

No public properties are explicitly exposed for the ContextMenu component.

API reference

class

ContextMenu

public sealed partial class ContextMenu : Layer<ContextMenu>, IContainer<ContextMenu, ContextMenu.Item>

A right-click / hover-driven popup menu with support for items, headers, dividers and arbitrarily deep nested submenus.

Constructors

Constructor
ContextMenu
public ContextMenu()

Initializes a new instance of this class.

Methods

Method
ContextMenu.Clear
public void Clear()

Clears the component's current state.

Method
ContextMenu.Replace
public void Replace(Item newComponent, Item oldComponent)

Replaces an existing item with a new one.

Method
ContextMenu.Add
public void Add(Item component)

Adds the given item to the component.

Method
ContextMenu.OnHide
public ContextMenu OnHide(Action onHidden)

Registers a callback invoked when the hide event fires.

Method
ContextMenu.Render
public override HTMLElement Render()

Renders the component's root HTML element.

Method
ContextMenu.Show
public override ContextMenu Show()

Shows the component.

Method
ContextMenu.ShowFor
public void ShowFor(IComponent component, int distanceX = 1, int distanceY = 1)

Shows the for.

Method
ContextMenu.ShowAt
public void ShowAt(int x, int y, int minWidth)

Shows the at.

Method
ContextMenu.ShowFor
public void ShowFor(HTMLElement element, int distanceX = 1, int distanceY = 1)

Shows the for.

Method
ContextMenu.Hide
public override void Hide(Action onHidden = null)

Hides the component.

Method
ContextMenu.Items
public ContextMenu Items(params Item[] children)

Adds the given items to the component.

class

ContextMenu

public sealed partial class ContextMenu

A right-click / hover-driven popup menu with support for items, headers, dividers and arbitrarily deep nested submenus.

Samples

Basic ContextMenu with Standard Items

This sample demonstrates how to instantiate a ContextMenu, add standard menu items including a divider and a disabled item, and then show the menu relative to a button click.

ContextMenu with Submenus

This sample demonstrates a ContextMenu that includes items with submenus. Submenus are defined by creating additional ContextMenu instances and attaching them to a parent menu item.

See also

  • ContextMenuItem: a nested item type used by ContextMenu to define individual menu entries.
  • Toast: Use Toast to provide user feedback when commands are executed.
  • Dialog, Panel: Other surface components that manage overlays and user interactions.

Referenced by

© 2026 Tesserae. All rights reserved.