Skip to content

搜索字段(Search field) ​

ui.SearchField 创建一个用于搜索的字段,编辑一个 *string:包含放大镜图标、文本,以及一个在有内容时清除它的按钮(Escape 键此时也能做到)。为空时它显示 "Search",或由 Placeholder 设置文字来说明搜索对象。Changed 报告变化,Submitted 报告 Enter。

go
if ui.SearchField(c, &app.query).Label("Search mail").Changed() {
	app.filter()
}

ui.SearchField(c, &app.pageQuery).Placeholder("Search pages, or #tag to filter")

若要随用户输入即时搜索,请在 Changed 时过滤;对于耗时较长的搜索,请在 Submitted 时搜索,或用 c.After 在停顿之后再搜索。

无障碍 ​

辅助技术将其视为一个搜索字段(macOS 上为 AXSearchField),由 Label 命名。