To activate the context menu the user must left click or press enter on the trigger element.
By default the menu will be positioned inline and will open to the bottom left
of the trigger element on hover or stay open if the trigger element is clicked.
The context menu also shows the icon fa-solid fa-ellipsis with no text by default.
Both of these can be changed by setting the TriggerText and TriggerButtonCss parameters.
The menu can be configured to open in different directions by setting the RfContextMenu.DropDownPosition parameter.
The menu can be positioned in the four corners based on RfContextMenu.Position parameter.
The ChildContent of the RfContextMenu component can contain any number of RfContextMenuItem
and RfContextMenuLink components. The RfContextMenuDivider component can be used to create a divider
between groups of menu items.
<RfContextMenu >
<RfContextMenuItem>Some Text</RfContextMenuItem>
<RfContextMenuItem>Some other text</RfContextMenuItem>
<RfContextMenuDivider />
<RfContextMenuLink Href="#">Link</RfContextMenuLink>
</RfContextMenu>
RfContextMenuItem
The RfContextMenuItem is used to add no interactive text to the menu.
You can add any content you want inside the component including something that is interactive.
RfContextMenuLink
The RfContextMenuLink component supports the OnClick event as well as all the parameters of the <a> tag.
Menu Ids
Each RfContextMenu renders its menu with an id of the form
context-menu-N and points the trigger's aria-controls at it. The number is unique
for every instance in the app and stays the same for the life of the instance, so
aria-controls always resolves to exactly one menu, even with many menus on one page. Treat the
number as opaque: it is a per-process counter, not something to hard code in CSS or JavaScript. Target a
menu through your own CssClass instead.
Dynamic / Lazy Loading
You can make the menu dynamically load items by binding to @bind-IsActive:after.
However, you will have to set IsHoverable to false because the hover action is controlled by css and a event cannot be triggered on hover.
In the same way you can add a the css class .is-loading to the TriggerButtonCss during the loading state to show a loading spinner.
Dynamic Loading Example
<RfContextMenu @bind-IsActive:after=@LoadContextMenu
TriggerButtonCss="@Rf.ClassWhen(("is-loading", IsLoaded))">
@if(IsLoaded == true)
{
<RfContextMenuItem>Some Text</RfContextMenuItem>
<RfContextMenuItem>Some other text</RfContextMenuItem>
<RfContextMenuDivider />
<RfContextMenuLink Href="#">Link</RfContextMenuLink>
}
</RfContextMenu>
CSS Variables
RfContextMenu adds additional CSS variables applied at the root .dropdown.
| CSS Variable |
Value |
--rf-position-spacing |
0 |