/
Dark Light
System
Default LBBW Jira Confluence Source Code
Share
Playground

Context Menu

<afp-context-menu> Since 1.10.0 stable This component uses the light DOM, so its markup and styles are part of the regular document flow.

A context menu component that displays a popover with menu items on right-click. It suppresses the default context menu.

Project Report Q1
2.4 MB · Modified today
Rename Move to folder Duplicate Delete

Examples #

Icons & Shortcuts #

Use afp-icon inside menu items and the details slot for keyboard shortcuts.

index.ts
TypeScript · 4.2 KB
Cut Copy Paste Rename Delete

Badges #

Use afp-badge in the details slot to show status labels or counters alongside menu items.

Inbox
12 unread messages
Mark all as read 12 Archive all Flag for follow-up 3 Delete all

Sliders #

The menu slot accepts any content — for example sliders for quick inline adjustments.

hero.jpg
JPEG · 3.2 MB

Switches #

Use switches inside the menu slot for inline preference toggles.

Document
Right-click for settings
Auto-save

Click Handler #

Listen for the afp-click event on menu items to react to selections. Use value to identify which item was clicked.

report.pdf
PDF · 1.8 MB
Rename Move to folder Delete

Placement #

Use the placement attribute to control which side of the cursor the menu appears on. Leave it empty (default) for automatic placement based on available space.

Bottom start
Rename Move Delete
Top start
Rename Move Delete
Right start
Rename Move Delete
Left start
Rename Move Delete

Available placements #

Placements can be combined and will be restricted to the provided options if more than two are given.

Primary Variants
top top-start, top-end
right right-start, right-end
bottom bottom-start, bottom-end
left left-start, left-end

Duration #

Use the duration attribute to control the open/close animation in milliseconds. Set to 0 to disable animations.

archive.zip
Slow animation (500ms)
Rename Move to folder Delete

Programmatic Usage #

Use showPopoverFromMouseEvent to trigger the context menu from any element — for example inside a canvas or a custom list.

Custom trigger
Right-click me
Rename Move to folder Delete

Notes #

The Context Menu component is built on top of the Popover component and inherits its positioning options.

placement controls on which side of the cursor the menu opens. duration sets the transition timing. For a full reference of inherited options, see the Popover documentation.

Properties

Learn more about properties.

Name Description Reflects
placement
The preferred placement of the context menu. Note that the actual placement may vary as needed to keep the panel inside of the viewport. If set to an empty array ([]), it enables auto placement. If containing more than two items, it is automatically restricted to the provided placements. You can also input a space-separated string.
Type
AfpPlacement
Name Description
TOP
Top placement.
RIGHT
Right placement.
BOTTOM
Bottom placement.
LEFT
Left placement.
TOP_START
Top-start placement.
TOP_END
Top-end placement.
RIGHT_START
Right-start placement.
RIGHT_END
Right-end placement.
BOTTOM_START
Bottom-start placement.
BOTTOM_END
Bottom-end placement.
LEFT_START
Left-start placement.
LEFT_END
Left-end placement.
AfpPlacement
Default []
duration
The duration of the show/hide animation in milliseconds. This value is passed to the popover component to control the transition duration.
Type number
Default 150

Methods

Learn more about using methods.

Name Description Arguments
hidePopover
Hides the popover if it is currently shown.
-
showPopoverAt
Shows the popover at the specified coordinates.
x<number> — The horizontal position in viewport pixels.
y<number> — The vertical position in viewport pixels.
showPopoverFromMouseEvent
Shows the popover at the mouse event coordinates. This is typically called on a right-click event.
e<MouseEvent> — The mouse event containing the coordinates where the popover should be shown.

Events

Learn more about events.

Name Return Description
afp-show void
Emitted when the context menu is shown.
afp-after-show void
Emitted after the context menu has been shown and transitions complete.
afp-hide void
Emitted when the context menu is hidden.
afp-after-hide void
Emitted after the context menu has been hidden and transitions complete.

Slots

Learn more about slots.

Name Description
content
The content that triggers the context menu on right-click.
menu
The context menu items to be displayed in the popover.

CSS Parts

Learn more about CSS Parts.

Name Description Selector
base
The component's base wrapper.
::part(base)
popover-base
The popover's base container.
::part(popover-base)

CSS Custom Properties

Name Description Default
--afp-context-menu-max-height
The maximum height of the context menu panel.
15rem
--afp-context-menu-min-width
The minimum width of the context menu panel.
auto

Dependencies

The component automatically brings in the listed items, including any nested dependencies that may exist.

Component CSS Part Prefix
afp-popover
popover-base - The popover's base container.

Importing

Using the bundle is the recommended method to include components. If you’d rather handle imports manually, you can use the code examples below.

import '@afp-design-system/core/dist/components/context-menu/context-menu.js';
esc
Share
Create a link with a predefined theme that is automatically applied when the generated link is opened. Default LBBW Presentation Mode
Abort Copy Link