Raxol.UI.Components.Input.Menu (Raxol v2.6.0)

View Source

A nested menu component with keyboard navigation.

Supports flat and nested menus with the same component. Only one submenu chain can be open at a time (standard menu behavior).

Item data format:

%{id: atom, label: string, children: [item], disabled: boolean, shortcut: string | nil}
  • children: [] = leaf (selectable action item)
  • children: [...] = submenu parent
  • disabled: true = rendered dimmed, skipped during navigation
  • shortcut = optional hint text rendered right-aligned (e.g. "Ctrl+S")

Keyboard bindings:

  • Up/Down: move cursor through visible items (skip disabled), clamped
  • Right: open submenu of current item (if it has children)
  • Left: close current submenu level, move cursor to parent
  • Enter/Space: fire on_select for leaf items; open submenu for parents
  • Home/End: jump to first/last visible non-disabled item
  • Escape: close deepest open submenu (or pass through)

Summary

Functions

Recursively searches for an item by id.

Finds the parent of an item by id. Returns nil if it's a root item or not found.

Returns a flat list of {item, depth} tuples for all currently visible items, respecting the open_path. Only the single open submenu chain is expanded.

Types

menu_item()

@type menu_item() :: %{
  id: atom(),
  label: String.t(),
  children: [menu_item()],
  disabled: boolean(),
  shortcut: String.t() | nil
}

t()

@type t() :: %{
  id: String.t() | atom(),
  items: [menu_item()],
  cursor: atom() | nil,
  open_path: [atom()],
  focused: boolean(),
  on_select: (atom() -> any()) | nil,
  style: map(),
  theme: map()
}

Functions

broadcast(msg)

command(cmd)

find_item(list, id)

@spec find_item([menu_item()], atom()) :: menu_item() | nil

Recursively searches for an item by id.

find_parent(nodes, id)

@spec find_parent([menu_item()], atom()) :: menu_item() | nil

Finds the parent of an item by id. Returns nil if it's a root item or not found.

mount(state)

Callback implementation for Raxol.UI.Components.Base.Component.mount/1.

schedule(msg, delay)

unmount(state)

Callback implementation for Raxol.UI.Components.Base.Component.unmount/1.

update(props, state)

Callback implementation for Raxol.UI.Components.Base.Component.update/2.

visible_items(map)

@spec visible_items(t()) :: [{menu_item(), non_neg_integer()}]

Returns a flat list of {item, depth} tuples for all currently visible items, respecting the open_path. Only the single open submenu chain is expanded.