Skip to main content
Neural UIv2.1.0Documentation
View v1

ContextMenu

Offer actions for the item a user is working with.

Category
Overlays
Import
@neural-ui/core/context-menu
Selector
[neuContextMenu]
import { NeuContextMenuDirective } from '@neural-ui/core/context-menu';

Overview

Attach the directive to the target for contextual actions. Give each item a stable key and handle the selected item in your application. Provide a visible action button so the same choices are available on touch.

Try it

Right-click the PDF card, focus it and press Shift+F10, or tap its options button. View details reveals the file metadata. Archive and Restore file update the cardโ€™s local state; no file or server is changed. The item template receives each item through let-item.

Try it
Invoice 248.pdfPDF ยท 128 KB

In recent documents

Right-click the file or open its options button.

State and events

The application owns the menu items, visible file details and archive state. openAt(x, y, origin) opens at viewport coordinates and restores focus to the supplied origin. The directive handles native contextmenu and ContextMenu/Shift+F10; the visible options button provides an explicit touch path.

Accessibility and keyboard

Use a visible native button for the direct action path and a meaningful label for each item. Keep a custom item template presentational; the menu already provides the interactive element.

Key
Action
Context Menu / Shift + F10 Open the context menu from the focused target.
โ†‘ / โ†“ Move between menu items.
Enter / Space Activate the focused option.
Escape Close the menu and return focus to the trigger.

API

Import the directive from its public entry point and attach it to a host element.

Inputs

Configure the component with [property]="value". Your application supplies these values; the component does not replace the state you pass in.

Name
Type
Default
Template binding
Description
neuContextMenuNeuContextMenuItem[][][neuContextMenu]Available items. Each action has a key and visible label.
neuContextMenuDisabledbooleanfalse[neuContextMenuDisabled]Suppress opening while true.

Outputs

Listen to an event with (event)="handler($event)". The table explains the data your handler receives and how to use it.

Name
Payload
Template binding
Description
menuClosedvoid(menuClosed)="onMenuClosed($event)"Emits when the menu closes.
menuItemClickNeuContextMenuItem(menuItemClick)="onMenuItemClick($event)"Emits the activated NeuContextMenuItem.
menuOpenedvoid(menuOpened)="onMenuOpened($event)"Emits when the menu opens.

Templates

ng-content projects content into the component. TemplateRef inputs receive a template; ng-template directives identify templates with a typed context. A directive shared by an entrypoint is not necessarily a slot of this component.

Name
Mechanism
Contract
NeuContextMenuItemDirective Public template directive (entrypoint)ng-template[neuContextMenuItem]

Usage example

Content between the button tags is projected content. You can supply text, an icon component or an SVG; the Icons section demonstrates these variants. For iconOnly, omit visible text and provide ariaLabel: projected content is not automatically removed.

Customize content
Invoice 248.pdfPDF ยท 128 KB

In recent documents

Right-click the file or open its options button.

Public methods

Name
Contract
closeclose(): void;
openAtopenAt(x: number, y: number, origin?: HTMLElement | null, onClose?: () => void): void;

Public Types

Open a type to inspect its definition and interface fields.

Styles and tokens

Use the public menu tokens to style the menu. Shared tokens affect other menus that use them.

Specific tokens

Token
Purpose
State / variant
Default / source
Fallback
--neu-context-menu-bg Inherited theme value used by this component Field surface var(--neu-surface)Root declaration--neu-surface
--neu-context-menu-border Inherited theme value used by this component Field surface var(--neu-border-color)Root declaration--neu-border-color
--neu-context-menu-color Inherited theme value used by this component Field surface var(--neu-text-primary)Root declaration--neu-text-primary
--neu-context-menu-disabled-color Inherited theme value used by this component Field surface var(--neu-text-muted)Root declaration--neu-text-muted
--neu-context-menu-hover Inherited theme value used by this component Field surface var(--neu-surface-2)Root declaration--neu-surface-2

Shared tokens used

Override these on a local wrapper to affect this example. An override on :root affects other components that use the same token.

Token
Purpose here
Other impact
Default / fallback
--neu-error Invalid field or danger-action color Shared by other Core consumers; scope the override. #dc2626
--neu-focus-ring Normal keyboard-focus ring Shared by other Core consumers; scope the override. 0 0 0 var(--neu-focus-ring-width) rgba(0, 122, 255, 0.15)
--neu-radius Control corner radius Shared by other Core consumers; scope the override. 8px
--neu-surface-2 Secondary surfaces and alternating rows Shared by other Core consumers; scope the override. #f1f5f9
--neu-text Main text and inherited icon color Shared by other Core consumers; scope the override. #0f172a
--neu-text-muted Secondary labels and supporting content Shared by other Core consumers; scope the override. #475569
--neu-border-color Inherited theme value used by this component Shared by other Core consumers; scope the override. var(--neu-border)
--neu-radius-lg Corner radius Shared by other Core consumers; scope the override. 12px