SutraUI.Command (Sutra UI v0.3.0)
View SourceA command palette component for fast keyboard-driven navigation and actions.
Command palettes provide a searchable, keyboard-navigable list of commands or options. They can be used inline or as a modal dialog.
Examples
# Inline command menu
<.command id="actions" placeholder="Search actions...">
<.command_group heading="Actions">
<.command_item id="new-file" phx-click="new_file">New File</.command_item>
<.command_item id="open-file" phx-click="open_file">Open File</.command_item>
</.command_group>
<.command_separator />
<.command_group heading="Settings">
<.command_item id="preferences">Preferences</.command_item>
</.command_group>
</.command>
# Modal command palette (Cmd+K style)
<.command_dialog id="cmd-palette">
<.command_group heading="Navigation">
<.command_item id="home" keywords={["index", "main"]}>Home</.command_item>
<.command_item id="settings" keywords={["preferences", "config"]}>Settings</.command_item>
</.command_group>
</.command_dialog>Accessibility
- Full keyboard navigation (Arrow keys, Home, End, Enter, Escape)
- Search/filter functionality with live updates
- Proper ARIA roles and attributes
- Focus management
Summary
Functions
Renders an inline command menu.
Renders a modal command dialog (Cmd+K style).
Renders a command group with an optional heading.
Renders a command item.
Renders a separator between command items or groups.
Hides a command dialog by ID.
Shows a command dialog by ID.
Functions
Renders an inline command menu.
Attributes
id(:string) (required) - Unique identifier for the command.placeholder(:string) - Search input placeholder. Defaults to"Type a command or search...".empty_text(:string) - Text shown when no results match. Defaults to"No results found.".class(:string) - Additional CSS classes. Defaults tonil.- Global attributes are accepted. Additional HTML attributes.
Slots
inner_block(required) - Command items and groups.
Renders a modal command dialog (Cmd+K style).
Attributes
id(:string) (required) - Unique identifier for the command dialog.placeholder(:string) - Search input placeholder. Defaults to"Type a command or search...".empty_text(:string) - Text shown when no results match. Defaults to"No results found.".class(:string) - Additional CSS classes. Defaults tonil.- Global attributes are accepted. Additional HTML attributes.
Slots
inner_block(required) - Command items and groups.
Renders a command group with an optional heading.
Attributes
heading(:string) - Group heading text. Defaults tonil.class(:string) - Additional CSS classes. Defaults tonil.- Global attributes are accepted. Additional HTML attributes.
Slots
inner_block(required) - Command items in this group.
Renders a command item.
Attributes
id(:string) (required) - Unique identifier for the item.keywords(:list) - Additional search keywords. Defaults to[].disabled(:boolean) - Whether the item is disabled. Defaults tofalse.class(:string) - Additional CSS classes. Defaults tonil.- Global attributes are accepted. Additional HTML attributes. Supports all globals plus:
["phx-click", "phx-value-id"].
Slots
inner_block(required) - The item content.
Renders a separator between command items or groups.
Hides a command dialog by ID.
Examples
<button phx-click={PhxUI.Command.hide_command_dialog("cmd-palette")}>Close</button>
Shows a command dialog by ID.
Examples
<button phx-click={PhxUI.Command.show_command_dialog("cmd-palette")}>Open</button>