命令搜索#

生产 Command 组合输入快照与调用方筛选的结果。

启用 JavaScript 后可运行预览;源码和安装命令仍可直接查看。

用法
results := tree.Sub(page, tree.Name("item"))
command := components.BeginCommand(canvas, theme, bounds, components.CommandOptions{
    InputID: inputID, Query: query, Placeholder: "Type a command…", Layer: 1,
})
command.AddGroup("Suggestions")
command.AddItem(components.CommandItem{ID: results.At(0), Label: "Open workspace",
    Shortcut: "⌘O", Selected: selected == 0})
command.AddItem(components.CommandItem{ID: results.At(1), Label: "Create window",
    Shortcut: "⌘N", Selected: selected == 1})
if index, ok := canvas.ClickedIn(results); ok {
    selected = int(index)
}

对话框尺寸#

更宽松的命令面板行高和已选状态。

启用 JavaScript 后可运行预览;源码和安装命令仍可直接查看。

用法
results := tree.Sub(page, tree.Name("item"))
command := components.BeginCommand(canvas, theme, bounds, components.CommandOptions{
    InputID: inputID, Query: "open", Placeholder: "Type a command…",
    Variant: components.CommandDialog, Layer: 1,
})
command.AddItem(components.CommandItem{
    ID: results.At(0), Label: "Open workspace", Shortcut: "⌘O", Selected: true,
})
command.AddSeparator()
command.AddItem(components.CommandItem{
    ID: results.At(2), Label: "Pin current view", Checked: checked, Disabled: true,
})

空结果#

使用生产空结果行而不伪造列表。

启用 JavaScript 后可运行预览;源码和安装命令仍可直接查看。

用法
command := components.BeginCommand(canvas, theme, bounds, components.CommandOptions{
    InputID: inputID, Query: query, Placeholder: "Type a command…", Layer: 1,
})
command.AddEmpty("No commands found")
command.End()

安装

将组件源码复制到自己的项目,直接修改。

仓库命令
go run ./cmd/viva add --out ./components/local command

源码组件用法#

此预览直接调用生产 Go 组件。稳定 ID、值与打开状态仍由应用持有;组件只负责绘制并声明交互语义。

  • 标题旁的源码链接列出了全部选项与视觉决策。
  • 请使用原生命令验证系统文本、焦点、无障碍与平台集成。
  • 浏览器预览验证共享布局和场景行为,不代表原生性能。

验证边界#

示例覆盖当前 API 的代表性状态,但不表示每个桌面后端都已完成真机验证。

键盘操作

Tab 在控件间移动;Ctrl/⌘ K 搜索组件。进入预览后,键盘事件由 Go 运行时处理。