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
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.
- Namespace
- Tesserae
- Inheritance
- Layer<ContextMenu> → ContextMenu
- Implements
- IContainer<ContextMenu, ContextMenu.Item>
Constructors
| Name | Description |
|---|---|
| ContextMenu | Initializes a new instance of this class. |
Methods
| Name | Description |
|---|---|
| Clear | Clears the component's current state. |
| Replace | Replaces an existing item with a new one. |
| Add | Adds the given item to the component. |
| SidePanel | Shows a panel of free content beside the menu's items, inside the same popup - details about the target, actions that do not read as menu rows. The panel is not a row: the arrow keys walk past it, and clicking inside it does not close the menu, so anything in it that should close the menu calls Hide itself. Call it before the menu is shown. |
| OnHide | Registers a callback invoked when the hide event fires. |
| Render | Renders the component's root HTML element. |
| Show | Shows the component. |
| ShowFor | Shows the for. |
| ShowAt | Shows the at. |
| Hide | Hides the component. |
| Items | Adds the given items to the component. |
public void Replace(Item newComponent, Item oldComponent)Replaces an existing item with a new one.
public ContextMenu SidePanel(IComponent panel)Shows a panel of free content beside the menu's items, inside the same popup - details about the target, actions that do not read as menu rows. The panel is not a row: the arrow keys walk past it, and clicking inside it does not close the menu, so anything in it that should close the menu calls Hide itself. Call it before the menu is shown.
public ContextMenu OnHide(Action onHidden)Registers a callback invoked when the hide event fires.
public override HTMLElement Render()Renders the component's root HTML element.
| Overload | |
|---|---|
| ShowFor(IComponent, int, int) | Shows the for. |
| ShowFor(HTMLElement, int, int) | Shows the for. |
public sealed partial class ContextMenuA right-click / hover-driven popup menu with support for items, headers, dividers and arbitrarily deep nested submenus.
- Namespace
- Tesserae
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.