Skip to content

Menu ​

A dropdown menu of actions behind a button.

Courier, with status emails.

Put the button into the trigger slot and bind the slot's attrs to it. Build the menu from these parts:

  • NuiMenuItem runs an action or opens a link.
  • NuiMenuCheckboxItem turns an option on and off.
  • NuiMenuRadioGroup with NuiMenuRadioItem picks one option of several.
  • NuiMenuSub opens a nested menu.
  • NuiMenuLabel names a group of items.
  • NuiMenuSeparator draws a line between groups.

Installation ​

ts
import { NuiMenu, NuiMenuItem } from '@numior/kit';

Usage ​

Open the menu and change its side, its distance from the button and closing after a choice.

Side of the trigger the menu opens on, such as bottom-start.

Distance from the trigger in pixels. Defaults to 4, as for every dropdown list.

Examples ​

Describe a menu with an array ​

Pass the items in items.

Order 20411, Nina Hart

The order is awaiting payment.

Each entry is an object, and its type field sets the kind of the entry:

typeEntryFields
none or itemAn action or a linklabel, icon, shortcut, tone, href, to, onSelect
checkboxAn option with a checklabel, icon, checked, onCheckedChange
radio-groupA choice of one optionvalue, items, onChange
subA nested menulabel, icon, items
labelA group headinglabel
separatorA line between groupsnone

Behavior ​

  • A click on the button opens the menu with no item highlighted. ArrowDown then goes to the first item and ArrowUp to the last one.
  • Enter, Space or ArrowDown on the button open the menu at the first item, and ArrowUp at the last one.
  • The pointer highlights the item under it without the focus ring, which comes back with the first key press.
  • Choosing an item closes the menu, and :close-on-select="false" keeps it open. A checkbox item keeps the menu open by default, so the user can check several options.
  • A nested menu opens on hover after a short delay, or with Enter or ArrowRight. A click outside closes every level at once.

Accessibility ​

A screen reader announces that the button opens a menu and whether the menu is open. Checkbox and radio items are announced as checked or not checked.

When the menu closes from the keyboard, the focus returns to the button. Arrow keys skip disabled items, and an item with href or to is a link.

Keys
Action
↓
On the trigger, opens the menu at the first item. Inside, moves to the next item.
↑
On the trigger, opens the menu at the last item. Inside, moves to the previous item.
↵
Picks the item or opens the submenu.
Space
Picks the item or opens the submenu.
→
Opens the submenu. Closes it in right-to-left layouts.
←
Closes the submenu. Opens it in right-to-left layouts.
Home
Moves to the first item.
End
Moves to the last item.
Esc
Closes the open submenu or the menu itself.
⇥
Closes the whole menu.

API ​

NuiMenu

Props

Name
Type
Default
Description
id
string
—
Id of the menu. Generated automatically by default.
placement
Placement
"bottom-start"
Side of the trigger the menu opens on, such as bottom-start.
offset
number
FLOATING_OFFSET
Distance from the trigger in pixels. Defaults to 4, as for every dropdown list.
items
readonly NuiMenuEntry[]
—
Menu entries as an array instead of child components.
closeOnSelect
boolean
true
Closes the menu after an item is picked.
loop
boolean
true
Arrow keys wrap from the last item to the first and back.
typeahead
boolean
true
Moves focus to an item when the user types its first letters.
label
string
—
Menu label for screen readers. Without it, the trigger text labels the menu.
anchor
HTMLElement | null
—
Element in place of the trigger slot, such as a table cell. Open the menu with show. Focus returns to the element on close.
compact
boolean
false
Removes the minimum menu width. Suits icon-only items.
lazy
boolean
false
Creates the items on the first open. Suits large menus in tables, not navigation: the server renders no items.

Models

Name
Type
Default
Description
v-model:open
boolean
false
Whether the menu is open.

Slots

Name
Slot props
Description
trigger
NuiMenuTriggerSlot
Button that opens the menu. Receives attrs for v-bind and open.
default
any
Items, groups and separators of the menu.

Exposed

Name
Type
Description
triggerElement
HTMLElement | null
The trigger slot button element while the menu is mounted.
show
(focus?: NuiMenuFocus | undefined) => void
Opens the menu. With first or last, focuses the first or last item.

NuiMenuItem

Props

Name
Type
Default
Description
icon
IconSource
—
Icon before the label, such as settings.
shortcut
string
—
Keyboard shortcut at the end of the row, such as Ctrl+C.
disabled
boolean
false
Disables the item: it stays visible but cannot be picked.
tone
NuiMenuItemTone
"neutral"
Color of the item: neutral, or a red error for destructive actions such as deleting.
closeOnSelect
boolean
—
Closes the menu after picking. Overrides closeOnSelect of the menu.
href
string
—
Address the item points to. The item becomes a link.
to
string | object
—
Route for RouterLink, NuxtLink or the configured link. Without a router, a string becomes href.
as
string | Component
—
Link component for to in place of the app router.

Events

Name
Payload
Description
select
[]
Fires when the item is picked with the keyboard or the mouse.

Slots

Name
Slot props
Description
default
any
Text of the item.
trailing
any
Content at the end of the row, for example a check mark.

NuiMenuCheckboxItem

Props

Name
Type
Default
Description
icon
IconSource
—
Icon before the label, such as settings.
disabled
boolean
false
Disables the item: it stays visible but cannot be picked.
closeOnSelect
boolean
false
Closes the menu after toggling.

Models

Name
Type
Default
Description
v-model:checked
boolean
false
Whether the item is checked.

Events

Name
Payload
Description
select
[]
Fires when the item is picked with the keyboard or the mouse.

Slots

Name
Slot props
Description
default
{}
Text of the item.

NuiMenuRadioGroup

Props

Name
Type
Default
Description
getKey
NuiOptionKey<NonNullable<T>>
—
Function that returns the key of an object value; the selected item is found by this key. Without it the JSON of the value is the key.

Models

Name
Type
Default
Description
v-model
T
—
Value of the selected item.

Slots

Name
Slot props
Description
default
{}
NuiMenuRadioItem items.

NuiMenuRadioItem

Props

Name
Type
Default
Description
valuerequired
T
—
Value the group v-model receives.
icon
IconSource
—
Icon before the label, such as settings.
disabled
boolean
false
Disables the item: it stays visible but cannot be picked.
closeOnSelect
boolean
true
Closes the menu after picking.

Events

Name
Payload
Description
select
[]
Fires when the item is picked with the keyboard or the mouse.

Slots

Name
Slot props
Description
default
{}
Text of the item.

NuiMenuLabel

Slots

Name
Slot props
Description
default
{}
Group heading text.

NuiMenuSeparator

NuiMenuSub

Props

Name
Type
Default
Description
id
string
—
Id of the submenu. Generated automatically by default.
label
string
—
Label of the item that opens the submenu.
icon
IconSource
—
Icon before the label, such as settings.
disabled
boolean
false
Disables the item: it stays visible but cannot be picked.
openDelay
number
100
Delay in milliseconds before the submenu opens on hover.
closeDelay
number
300
Delay in milliseconds before the submenu closes after the pointer leaves.

Slots

Name
Slot props
Description
label
any
Label markup in place of the label text.
default
any
Submenu items.

Edit this page

Search

Esc