Navigation
Nested Commands
A two-level palette: Enter on a command that takes a parameter drills into its subcommands, and Backspace on an empty query steps back out.
- command
- palette
- nested
- keyboard
Preview
Use it with AI
- 1. Copy the link.
- 2. Write to your agent in your own words and drop the link into the sentence.
- 3. The agent opens the link and installs the component from the registry.
put this in the header: https://vibeui.ru/c/command-004?lang=en
- Сменить тему
- Создать
- Экспорт реестра
- Пересобрать индексы
- Открыть документацию
Enter — открыть подкоманды · Esc — сброс
Show the full instructions
What the link says, spelled out. Use it when your agent cannot open links — paste this text instead.
# Install and place "command-004" (Nested Commands) from VibeUI
## 1. Install first — do not skip, do not recreate
Run this exact command before writing any code:
npx shadcn@latest add https://vibeui.ru/r/command-004.json
Registry item: https://vibeui.ru/r/command-004.json
Installs to: components/vibeui/command-004.tsx (the exact path follows this project's components.json aliases).
npm dependencies: none.
Registry dependencies: none.
Install it from the registry. Do not recreate it from the description,
do not substitute a similar component from another library, and do not
rewrite it to match the project's existing style.
## 2. What it is
A two-level palette: Enter on a command that takes a parameter drills into its subcommands, and Backspace on an empty query steps back out.
A palette with nested subcommands: Enter drills in, a breadcrumb chip sits next to the field, and Backspace on an empty query steps back. Zero dependencies, one file.
## 3. How to use it
import { Command004 } from "@/components/vibeui/command-004"
<Command004 commands={[{ label: "Change theme", children: ["Light", "Dark"] }]} />
Read the installed file for the full prop list.
## 4. Where to place it
This is a small inline component. Put it exactly where the user asked,
inside the existing markup. Do not create a new page, section or
wrapper for it. If a similar control already sits in that spot,
replace it instead of adding a second one.
Placement: ___
(The user fills this line in. If it is still blank, ask where to put it
instead of guessing.)
## 5. Keep exactly as installed
- the local --vibeui-command-004-* palette — do not swap it for your theme tokens
- the level chip beside the field rather than breadcrumbs above the panel: context belongs where the caret is
- stepping back with Backspace on an empty query — the familiar gesture that saves aiming at a close button
- clearing the query when drilling in: the old filter does not apply to subcommands
- the chevron marking rows that nest: without it Enter behaves unpredictably
- the role=combobox plus aria-activedescendant pairing: focus stays in the field
## 6. You may change
- the commands array and its nested children
- the field hint through the placeholder prop
- the footer text with the key hints
- the accent through the accent prop
## 7. Rules
- There are exactly two levels: for a deeper tree keep the path as an array instead of one parent.
- Escape clears the query first and only then steps back — those are two distinct undo steps.
- Running a command only prints into the footer here: hook your own handler into choose.
- Do not lift the CSS variables into globals.css: the component has to stay a single file.
## 8. Verify
- it renders with no console errors;
- it looks like the preview on the VibeUI page you copied this from;
- if it does not, you changed something listed in section 5 — put it back.For developers
npx shadcn@latest add https://vibeui.ru/r/command-004.jsonhttps://vibeui.ru/r/command-004.jsonКомпонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-command-004-*. Клиентский: "use client" ради состояния уровня и запроса. Команда с массивом children не выполняется, а открывает второй уровень: запрос сбрасывается, слева от поля появляется чип-крошка с именем родителя, список сменяется подкомандами. Возврат назад повешен на Backspace при пустом запросе и на Escape, а также на крестик в чипе. Роли combobox, listbox и option объявлены явно.
Component source
The same file your agent installs. Here in case you would rather copy it by hand.
"use client"
import { useId, useState } from "react"
import type {
ComponentPropsWithoutRef,
CSSProperties,
KeyboardEvent,
} from "react"
export type Command004Command = {
label: string
children?: string[]
}
export type Command004Props = Omit<
ComponentPropsWithoutRef<"div">,
"children"
> & {
commands?: Command004Command[]
placeholder?: string
accent?: string
}
// Идея компонента: двухуровневая палитра. Команда с параметром («Сменить
// тему» → какую именно) не помещается в одну строку списка, поэтому Enter по
// такой строке не запускает её, а входит на второй уровень: слева от поля
// появляется чип-хлебная крошка, запрос сбрасывается, список сменяется
// подкомандами. Backspace на пустом запросе выходит обратно — это привычный
// жест, и он снимает необходимость целиться в крестик.
const STYLES = `
:where([data-vibeui-block="command-004"]){
--vibeui-command-004-bg:oklch(1 0 0);
--vibeui-command-004-fg:oklch(0.23 0.014 265);
--vibeui-command-004-muted:oklch(0.57 0.014 265);
--vibeui-command-004-border:oklch(0.9 0.006 265);
--vibeui-command-004-accent:oklch(0.55 0.2 300);
--vibeui-command-004-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="command-004"]{
display:block;box-sizing:border-box;width:100%;max-width:24rem;overflow:hidden;
background:var(--vibeui-command-004-bg);color:var(--vibeui-command-004-fg);
border:1px solid var(--vibeui-command-004-border);border-radius:0.875rem;
box-shadow:0 18px 40px -28px oklch(0.2 0.03 265 / 60%);
font-family:var(--vibeui-command-004-font);
}
[data-vibeui-block="command-004"] [data-part="field"]{
display:flex;align-items:center;gap:0.5rem;
padding:0 0.75rem;border-bottom:1px solid var(--vibeui-command-004-border);
}
/* Чип уровня заменяет крошки над полем: он рядом с курсором, где и мысль. */
[data-vibeui-block="command-004"] [data-part="crumb"]{
display:inline-flex;align-items:center;gap:0.375rem;flex:none;
padding:0.1875rem 0.5rem;border-radius:0.5rem;
background:color-mix(in oklab,var(--vibeui-command-004-accent) 15%,transparent);
color:var(--vibeui-command-004-accent);font-size:0.75rem;font-weight:700;
}
[data-vibeui-block="command-004"] [data-part="crumb"] button{
appearance:none;border:0;background:none;padding:0;cursor:pointer;
color:inherit;font:inherit;line-height:1;
}
[data-vibeui-block="command-004"] [data-part="crumb"] button:focus-visible{outline:2px solid currentColor;outline-offset:2px;border-radius:0.25rem}
[data-vibeui-block="command-004"] input{
flex:1;min-width:0;height:2.875rem;
appearance:none;border:0;background:none;color:inherit;
font:inherit;font-size:0.9375rem;outline:none;
}
[data-vibeui-block="command-004"] [data-part="field"]:focus-within{box-shadow:inset 0 -2px 0 0 var(--vibeui-command-004-accent)}
[data-vibeui-block="command-004"] [data-part="list"]{
list-style:none;margin:0;padding:0.3125rem;max-height:14rem;overflow-y:auto;
}
[data-vibeui-block="command-004"] [data-part="row"]{
display:flex;align-items:center;gap:0.75rem;
padding:0.4375rem 0.5625rem;border-radius:0.5rem;cursor:pointer;font-size:0.875rem;
}
[data-vibeui-block="command-004"] [data-part="row"]:hover,
[data-vibeui-block="command-004"] [data-part="row"][aria-selected="true"]{
background:color-mix(in oklab,var(--vibeui-command-004-accent) 12%,transparent);
}
[data-vibeui-block="command-004"] [data-part="row"] [data-part="more"]{
margin-left:auto;color:var(--vibeui-command-004-muted);font-size:0.75rem;
}
[data-vibeui-block="command-004"] [data-part="empty"]{
margin:0;padding:1.125rem 0.875rem;font-size:0.875rem;color:var(--vibeui-command-004-muted);
}
[data-vibeui-block="command-004"] [data-part="foot"]{
margin:0;padding:0.4375rem 0.875rem;
border-top:1px solid var(--vibeui-command-004-border);
font-size:0.6875rem;color:var(--vibeui-command-004-muted);
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="command-004"] *{animation:none!important;transition:none!important}}
`
const DEFAULT_COMMANDS: Command004Command[] = [
{
label: "Сменить тему",
children: ["Светлая", "Тёмная", "Как в системе"],
},
{
label: "Создать",
children: ["Компонент", "Блок", "Категорию"],
},
{
label: "Экспорт реестра",
children: ["JSON для shadcn", "Архив исходников"],
},
{ label: "Пересобрать индексы" },
{ label: "Открыть документацию" },
]
/**
* Двухуровневая палитра: Enter входит в подкоманды, Backspace на пустом
* запросе возвращает назад. Один файл, ноль зависимостей.
*/
export function Command004({
commands = DEFAULT_COMMANDS,
placeholder = "Команда…",
accent,
className,
style,
...props
}: Command004Props) {
const [query, setQuery] = useState("")
const [parent, setParent] = useState<Command004Command | null>(null)
const [active, setActive] = useState(0)
const [done, setDone] = useState<string | null>(null)
const listId = useId()
const rowId = useId()
const needle = query.trim().toLowerCase()
const source = parent
? (parent.children ?? []).map((label) => ({ label }))
: commands
const rows = source.filter((command) =>
command.label.toLowerCase().includes(needle),
)
const current = rows[Math.min(active, rows.length - 1)]
const back = () => {
setParent(null)
setQuery("")
setActive(0)
}
const choose = (command: Command004Command) => {
if (command.children && command.children.length > 0) {
setParent(command)
setQuery("")
setActive(0)
setDone(null)
return
}
setDone(parent ? `${parent.label}: ${command.label}` : command.label)
setQuery("")
setActive(0)
}
const onKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
event.preventDefault()
if (rows.length === 0) return
const step = event.key === "ArrowDown" ? 1 : -1
setActive((index) => (index + step + rows.length) % rows.length)
return
}
if (event.key === "Enter" && current) {
event.preventDefault()
choose(current)
return
}
// Backspace на пустом запросе — привычный выход на уровень выше.
if (event.key === "Backspace" && query.length === 0 && parent) {
event.preventDefault()
back()
return
}
if (event.key === "Escape") {
event.preventDefault()
if (query.length > 0) {
setQuery("")
setActive(0)
} else if (parent) {
back()
}
}
}
const paletteStyle = {
...(accent ? { "--vibeui-command-004-accent": accent } : null),
...style,
} as CSSProperties
return (
<>
<style href="vibeui-command-004" precedence="medium">
{STYLES}
</style>
<div
{...props}
data-vibeui-block="command-004"
className={className}
style={paletteStyle}
role="dialog"
aria-label="Командная палитра"
>
<div data-part="field">
{parent ? (
<span data-part="crumb">
{parent.label}
<button
type="button"
aria-label="Назад к списку команд"
onClick={back}
>
✕
</button>
</span>
) : null}
<input
type="text"
role="combobox"
aria-expanded={rows.length > 0}
aria-controls={listId}
aria-autocomplete="list"
aria-activedescendant={
current ? `${rowId}-${rows.indexOf(current)}` : undefined
}
aria-label={parent ? `${parent.label}: подкоманда` : placeholder}
placeholder={parent ? "Подкоманда…" : placeholder}
value={query}
onChange={(event) => {
setQuery(event.target.value)
setActive(0)
}}
onKeyDown={onKeyDown}
/>
</div>
{rows.length === 0 ? (
<p data-part="empty">
Здесь ничего нет. Сотрите запрос или вернитесь назад.
</p>
) : (
<ul id={listId} data-part="list" role="listbox" aria-label="Команды">
{rows.map((command, index) => (
<li
key={command.label}
id={`${rowId}-${index}`}
data-part="row"
role="option"
aria-selected={current?.label === command.label}
onClick={() => choose(command)}
>
{command.label}
{"children" in command && command.children ? (
<span data-part="more" aria-hidden="true">
›
</span>
) : null}
</li>
))}
</ul>
)}
<p data-part="foot" role="status">
{done
? `Выполнено: ${done}`
: parent
? "Backspace — назад · Enter — выполнить"
: "Enter — открыть подкоманды · Esc — сброс"}
</p>
</div>
</>
)
}