单选题#

选择一个桌面渲染后端并继续。

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

用法
choice := tree.Sub(page, tree.Name("choice"))
q := components.BeginQuestionnaire(canvas, theme, bounds, components.QuestionnaireData{
    Progress: "Question 2 of 5", Title: "What should Viva optimize first?",
    Description: "Answers stay in application state.",
})
for index, label := range []string{"Low memory", "Fast startup", "Small binaries"} {
    q.AddChoice(components.QuestionnaireChoice{
        ID: choice.At(index), Label: label, Checked: selected == index,
    })
}
q.PaintActions(components.QuestionnaireActions{
    PreviousID: tree.ID(page, "previous"), PreviousLabel: "Back",
    SkipID: tree.ID(page, "skip"), SkipLabel: "Skip",
    NextID: tree.ID(page, "next"), NextLabel: "Continue",
})
if index, ok := canvas.ClickedIn(choice); ok {
    selected = index
}

多选题#

切换多个性能目标,组件不隐藏答案状态。

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

用法
choice := tree.Sub(page, tree.Name("choice"))
q := components.BeginQuestionnaire(canvas, theme, bounds, components.QuestionnaireData{
    Progress: "Question 2 of 5", Title: "Which performance goals matter?",
    Description: "Answers stay in application state.",
    ChoiceType: components.QuestionnaireCheckbox,
})
for index, label := range []string{"Low memory", "Fast startup", "Small binaries"} {
    q.AddChoice(components.QuestionnaireChoice{
        ID: choice.At(index), Label: label, Checked: checked[index],
    })
}
if index, ok := canvas.ClickedIn(choice); ok {
    checked[index] = !checked[index]
}

安装

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

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

源码组件用法#

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

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

验证边界#

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

键盘操作

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