DropdownMenu
A menu of actions and links, navigable with the keyboard.
On this page
Examples
Dropdown menu
Last action: none
Razor
<div class="flex flex-col items-center gap-3">
<KlyDropdownMenu Items="Items" OnSelect="item => _last = item.Label">
<KlyButton Label="Options" Color="KlyColor.Neutral" Variant="ButtonVariant.Outline" data-testid="menu-trigger">
<TrailingIcon>@KlyIcons.Named("chevron-down")</TrailingIcon>
</KlyButton>
</KlyDropdownMenu>
<p class="text-sm text-(--klyroo-text-muted)" data-testid="menu-state">Last action: @(_last ?? "none")</p>
</div>
@code {
private string? _last;
private static readonly KlyMenuItem[] Items =
[
KlyMenuItem.Heading("My account"),
new() { Label = "Profile", Shortcut = "⌘P" },
new() { Label = "Billing", Shortcut = "⌘B" },
new() { Label = "Documentation", Href = "/docs" },
KlyMenuItem.Separator(),
new() { Label = "Archive", Disabled = true },
new() { Label = "Delete account", Color = KlyColor.Error },
];
}Submenus
An item with Children opens a nested menu: right arrow, Enter, a click or a pause of the pointer opens it, left arrow or Escape closes it.
Last action: none
Razor
<div class="flex flex-col items-center gap-3">
<KlyDropdownMenu Items="Items" OnSelect="item => _last = item.Label">
<KlyButton Label="Share" Color="KlyColor.Neutral" Variant="ButtonVariant.Outline" data-testid="submenu-trigger">
<TrailingIcon>@KlyIcons.Named("chevron-down")</TrailingIcon>
</KlyButton>
</KlyDropdownMenu>
<p class="text-sm text-(--klyroo-text-muted)" data-testid="submenu-state">Last action: @(_last ?? "none")</p>
</div>
@code {
private string? _last;
private static readonly KlyMenuItem[] Items =
[
KlyMenuItem.Heading("Share"),
new() { Label = "Copy link" },
new()
{
Label = "Send to",
Children =
[
new() { Label = "Email" },
new() { Label = "Message" },
new()
{
Label = "Team",
Children = [new() { Label = "Design" }, new() { Label = "Engineering" }],
},
],
},
new() { Label = "Export", Disabled = true, Children = [new() { Label = "PDF" }] },
KlyMenuItem.Separator(),
new() { Label = "Delete", Color = KlyColor.Error },
];
}API
KlyDropdownMenu
Button that opens a menu of items, with submenus, keyboard navigation and typeahead.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
Class |
string |
Classes added to the root element, merged last so they win over the theme. | |
Items (required) |
IReadOnlyList |
The entries. An item with Children opens a submenu; a heading followed by items and a separator makes a labelled group. | |
Open (@bind-Open) |
bool |
false |
Whether the menu is open. Bind it with @bind-Open when .NET needs the state. |
Placement |
KlyPlacement |
KlyPlacement. |
Where the menu sits against the trigger. Defaults to BottomStart . Values: Top, TopStart, TopEnd, Right, RightStart, RightEnd, Bottom, BottomStart, BottomEnd, Left, LeftStart, LeftEnd. |
Ui |
DropdownMenuUi |
Per-instance class overrides of the slots of the dropdown menu, see DropdownMenuUi . They are merged after the theme and the Class parameter wins on the root slot. |
Events
| Name | Type | Description |
|---|---|---|
OnSelect |
EventCallback |
Called with the activated item. Link items navigate instead, and items with children open their submenu. |
Slots
| Name | Type | Description |
|---|---|---|
ChildContent |
RenderFragment |
The trigger; it must contain a button. |
Ui slots
Ui takes a DropdownMenuUi with one class string per slot, merged after the theme.
| Slot | Styles |
|---|---|
Content |
Classes merged into the content slot of KlyDropdownMenu , after the theme and the app configuration. |
Group |
Classes merged into the group slot of KlyDropdownMenu , after the theme and the app configuration. |
Label |
Classes merged into the label slot of KlyDropdownMenu , after the theme and the app configuration. |
Separator |
Classes merged into the separator slot of KlyDropdownMenu , after the theme and the app configuration. |
Item |
Classes merged into the item slot of KlyDropdownMenu , after the theme and the app configuration. |
ItemIcon |
Classes merged into the itemIcon slot of KlyDropdownMenu , after the theme and the app configuration. |
ItemLabel |
Classes merged into the itemLabel slot of KlyDropdownMenu , after the theme and the app configuration. |
ItemShortcut |
Classes merged into the itemShortcut slot of KlyDropdownMenu , after the theme and the app configuration. |
ItemChevron |
The arrow at the end of an item that opens a submenu. |