Skip to content

Sender 对话输入框 ​

AI 对话组件。公开入口:Sender。

在线演示 ​

本页复用官方 Go gallery 的真实示例。下方可以切换场景、主题和深浅色;长页面支持滚动,复杂布局可以横向滚动或在独立页面打开。

Sender 对话输入框 · 在线体验真实 Go 组件
在独立页面打开 ↗

查看此场景的 Go 源码 ↗

示例代码 ​

以下是上方在线演示运行的 Go 源码(来自官方 gallery),点击标题展开。函数接收的 c *ui.Context 由窗口的 UI 循环每帧传入,接入方式见 Go GUI 入门。

Sender 对话输入框

gallery 演示 Sender 的具名 Render 函数,源码 page_chat.go#L167。

加载中…

API ​

签名与说明由 site/tools/compdoc 从 Go 源码和文档注释提取;点击名称跳到 Go API 参考 的对应条目。

入口函数 ​

ui.Sender ​

go
func Sender(c *Context, val *string) *SenderW

Sender adds a chat input bound to *val. Read Submitted each frame and clear *val after sending:

s := ui.Sender(c, &draft).Loading(busy).Commands(cmds)
if s.Submitted() { send(draft); draft = "" }
if s.Stopped() { cancel() }

返回 *SenderW,可链式调用的方法见 SenderW 方法。

SenderW 方法 ​

ui.SenderW:SenderW is the chat input: an auto-growing multi-line editor where Enter sends and Shift+Enter inserts a line break, with an attachment strip, @ / command suggestions, a toolbar and a send / stop button.

方法说明签名
A11yLabelA11yLabel sets the accessible name of the editor (default: placeholder).A11yLabel(s string) *SenderW
AttachButtonAttachButton shows a paperclip button in the toolbar (see AttachClicked; the application opens its file dialog).AttachButton() *SenderW
AttachClickedAttachClicked reports a click on the attach button.AttachClicked() bool
AttachmentsAttachments shows *files as removable chips above the editor; a click on a chip's remove button deletes it from the slice (see Removed).Attachments(files *[]ChatAttachment) *SenderW
AutoSizeAutoSize sets the visible rows the editor grows between (default 1..8).AutoSize(minRows, maxRows int) *SenderW
ChangedChanged reports an edit of the text this frame.Changed() bool
CommandsCommands suggests opts after '/' (shown as "/value label").Commands(opts []Option) *SenderW
DisabledDisabled disables the whole input.Disabled(on bool) *SenderW
HeaderHeader adds content at the top of the input (quoted message, context chips).Header(fn func()) *SenderW
IDID returns the editor's ID (focus it with c.SetFocus).ID() ID
LayoutLayout applies layout options to the outer frame.Layout(opts ...layout.Option) *SenderW
LoadingLoading shows the stop button instead of the send button; Enter does not send and Escape (or the button) reports Stopped.Loading(on bool) *SenderW
MaxLengthMaxLength limits the number of characters.MaxLength(n int) *SenderW
MentionsMentions suggests opts after '@' (filtered by what follows it).Mentions(opts []Option) *SenderW
PickedPicked returns the suggestion inserted this frame and its prefix.Picked() (prefix string, o Option, ok bool)
PlaceholderPlaceholder replaces the default placeholder.Placeholder(s string) *SenderW
RemovedRemoved returns the index of the attachment removed this frame.Removed() (int, bool)
StoppedStopped reports a click on the stop button (or Escape) while loading.Stopped() bool
SubmittedSubmitted reports Enter or a click on the send button with something to send (text or attachments).Submitted() bool
SuggestSuggest opens a suggestion list when prefix is typed at the start of the text or after a space; src returns the options for the text typed after it so far.Suggest(prefix string, src func(query string) []Option) *SenderW
ToolbarToolbar adds controls to the start of the bottom row (model select, mode switch …); the send button stays at the end.Toolbar(fn func()) *SenderW

相关链接 ​

本页由完整组件表、实际 gallery 注册信息和 Go 源码(site/tools/compdoc)生成;新增组件未接入演示时,文档构建会报错。场景中的表单、表格、图表和移动端屏幕使用示例数据。

以 MIT 许可发布