noora
Sign in

Menu

A list of actions or links that opens from a trigger. Every trigger opens the same menu, so items look and behave the same everywhere.

Default

Choosing an item sends on_select with its value and closes the menu. Destructive items go last.

<.menu id="menu-default" label="Actions">
  <.menu_item value="rename" label="Rename project" />
  <.menu_item value="duplicate" label="Duplicate project" />
  <.menu_item value="transfer" label="Transfer project…" />
  <.menu_separator />
  <.menu_item value="delete" label="Delete project" variant="destructive" />
</.menu>

Dots

trigger="dots" opens the menu from a dots button, for overflow actions on a row or card. The label names it for screen readers.

<.menu id="menu-dots" label="More actions" trigger="dots">
  <.menu_item value="logs" label="View build logs" />
  <.menu_item value="runs" label="View test runs" />
  <.menu_item value="analytics" label="View analytics" />
</.menu>

Disabled items

Disabled items stay in place and keyboard navigation skips them, including destructive ones.

<.menu id="menu-disabled" label="Manage">
  <.menu_item value="invite" label="Invite member" />
  <.menu_item value="transfer" label="Transfer ownership" sublabel="Admins only" disabled />
  <.menu_separator />
  <.menu_item value="remove" label="Remove member" variant="destructive" disabled />
</.menu>

Prefix and suffix

A 16px icon or 20px image before the label, and extra content such as a badge after it.

<.menu id="menu-prefix-icons" label="Edit">
  <.menu_item value="rename" label="Rename">
    <:icon><.pencil /></:icon>
  </.menu_item>
  <.menu_item value="copy" label="Copy link">
    <:icon><.copy /></:icon>
  </.menu_item>
  <.menu_item value="runners" label="Runners">
    <:icon><.settings /></:icon>
    <:extra><.badge label="New" color="primary" style="light-fill" /></:extra>
  </.menu_item>
</.menu>
<.menu id="menu-prefix-images" label="ios-app">
  <.menu_item value="ios-app" label="ios-app" truncate="middle" selected>
    <:image><img src="/images/build-systems/xcode.png" alt="" /></:image>
  </.menu_item>
  <.menu_item value="android-app" label="android-app" truncate="middle">
    <:image><img src="/images/build-systems/gradle.png" alt="" /></:image>
  </.menu_item>
  <.menu_item value="server" label="server" truncate="middle">
    <:image><img src="/images/build-systems/mix.png" alt="" /></:image>
  </.menu_item>
</.menu>

Shortcuts

Put a shortcut key in extra to show how to reach the action from the keyboard.

<.menu id="menu-shortcuts" label="File">
  <.menu_item value="new" label="New project">
    <:extra>
      <.shortcut_key size="small">⌘N</.shortcut_key>
    </:extra>
  </.menu_item>
  <.menu_item value="search" label="Search">
    <:extra>
      <.shortcut_key size="small">⌘K</.shortcut_key>
    </:extra>
  </.menu_item>
  <.menu_item value="settings" label="Settings">
    <:extra>
      <.shortcut_key size="small">⌘,</.shortcut_key>
    </:extra>
  </.menu_item>
</.menu>

Checkbox items

checked makes an item a checkbox for choosing several options. Items toggle in place and the menu stays open while people toggle.

<.menu id="menu-checkboxes" label="Columns">
  <.menu_item value="status" label="Status" checked={true} />
  <.menu_item value="duration" label="Duration" checked={true} />
  <.menu_item value="branch" label="Branch" checked={false} />
  <.menu_item value="ran-by" label="Ran by" checked={false} />
</.menu>
<.menu id="menu-checkbox-icons" label="Platforms">
  <.menu_item value="ios" label="iOS" checked={true}>
    <:icon><.device_mobile /></:icon>
  </.menu_item>
  <.menu_item value="macos" label="macOS" checked={false}>
    <:icon><.device_desktop /></:icon>
  </.menu_item>
  <.menu_item value="watchos" label="watchOS" checked={true}>
    <:icon><.device_watch /></:icon>
  </.menu_item>
</.menu>

Selected

selected marks the current choice with a check, for menus that pick one option.

<.menu id="menu-selected" label="Last 7 days">
  <.menu_item value="24h" label="Last 24 hours" />
  <.menu_item value="7d" label="Last 7 days" selected />
  <.menu_item value="30d" label="Last 30 days" />
</.menu>

Descriptions

A sublabel qualifies the label; a description adds a second line. With trigger="split" , the label runs on_action and the chevron opens the menu.

<.menu id="menu-descriptions" label="Copy page" trigger="split" on_action="copy_page">
  <.menu_item value="markdown" label="Copy as Markdown" sublabel="LLMs">
    <:icon><.copy /></:icon>
  </.menu_item>
  <.menu_item
    value="view"
    label="View as Markdown"
    description="Open this page as plain text in a new tab."
  >
    <:icon><.external_link /></:icon>
  </.menu_item>
</.menu>

Guidelines

  • Use a menu for actions on one thing, such as a project or a run. Keep it to about ten items.
  • Write labels as a verb and a noun in sentence case, such as Rename project. Add … only when the item opens a dialog.
  • Put destructive items last, after a separator, with a specific label such as Delete project.
  • Give an item either a 16px icon or a 20px image (an avatar or a logo). Keep leading content consistent within a menu so labels line up.
  • Use sublabel for a short qualifier and description for a sentence. A description makes the item two lines tall.
  • Mark the current choice with selected . It shows a check at the end of the item; it highlights like any other item only when hovered or reached with the keyboard.
  • Use checked for options people pick several of, such as visible columns. Items toggle as they're chosen, keep the menu open, and send on_select with the new checked .
  • Disable items that aren't available instead of hiding them, so the menu keeps its shape. Keyboard navigation skips them.
  • Long labels truncate. Use truncate="middle" for identifiers such as schemes, branches, and project names, so both ends stay readable; keep the default end truncation for actions.

API reference

<.menu>

Attribute Type Default Description
close_on_select
boolean
true
Whether choosing an item closes the menu. Checkbox items always keep it open.
disabled
boolean
false
Whether the trigger is disabled. A menu without items is disabled too, except a split button's main action.
id Required
string
–
Unique identifier for the menu
label Required
string
–
The button's label. With the dots trigger, it isn't shown but names the button for screen readers.
on_action
any
nil
With the split trigger, the event or Phoenix.LiveView.JS command the label button runs
on_open_change
string
nil
Event pushed when the menu opens or closes
on_select
string
nil
Event pushed when an item is chosen, with its value , and for a checkbox item the checked state it toggled to
placement
string
"bottom-start"
Where the menu opens relative to its trigger. It flips when there isn't room. "bottom-start""bottom""bottom-end""top-start""top""top-end""left-start""left""left-end""right-start""right""right-end"
trigger
string
"label"
What opens the menu: a button with the label, a square dots button for overflow actions, or the chevron of a split button whose label runs on_action "label""dots""split"

Also accepts global attributes.

Slot Description
inner_block
The menu's items and separators

<.menu_item>

Attribute Type Default Description
checked
boolean
nil
Makes the item a checkbox, checked or not, for choosing several options. Choosing it toggles it in place, keeps the menu open, and sends on_select with the new checked . Rendering it with a different checked overrides the toggle.
description
string
nil
A second line under the label. The item grows to fit it.
disabled
boolean
false
Whether the item is unavailable. Keyboard navigation skips it.
href
string
nil
Navigates to this URL with a full page load
label Required
string
–
The item's text
navigate
string
nil
Navigates to this LiveView
on_click
any
nil
Event or JS command run when the item is chosen. It runs alongside the menu's on_select , so handle a choice in one of them.
patch
string
nil
Patches the current LiveView
selected
boolean
false
Shows a check at the end of the item, for the current choice
sublabel
string
nil
Secondary text shown in parentheses after the label
truncate
string
"end"
How a label too long for the menu is shortened. end suits actions; middle keeps both ends of identifiers such as schemes, branches, and project names. "end""middle"
value Required
string
–
Identifies the item, so it must be unique within the menu; sent with the menu's on_select event
variant
string
"default"
destructive colors the item red, for actions such as deleting. Put these last, after a separator. "default""destructive"

Also accepts global attributes, including targetreldownload.

Slot Description
:extra
Trailing content before the check, such as a shortcut key or a badge
:icon
A 16px icon before the label
:image
A 20px image before the label, such as an avatar or a logo

<.menu_separator>

Also accepts global attributes.