跳到主要内容
menumenu tanreiexpand_morecontrasttranslate
tanreiexpand_more
开始使用WebReactSwiftUIJetpack ComposeFlutterReact Native预设你自己的设计系统与 AI 代理一起使用 Tanrei品牌设计令牌设计系统与定制Theme Studio颜色字体排印图标形状层级动效交互状态行为布局无障碍文字颜色令牌字阶令牌形状令牌层级令牌动效令牌状态令牌间距与度量令牌组件按钮主操作按钮分段按钮按钮组带菜单的按钮工具栏复制按钮复选框单选按钮开关纸片(Chip)菜单滑块滑块字段日历DateTimePicker字段组单选组复选框组下拉选择框下拉选择字段菜单栏文件上传文件选择器 进阶放置区文本输入框 进阶文本字段纸片字段字段组合框 进阶组合框字段数字输入框 进阶数字字段颜色输入框 进阶颜色字段一次性验证码输入框 进阶一次性验证码字段嵌入式文本输入框 进阶聊天输入栏卡片分隔线模态层 进阶对话框列表列表行底部面板侧边面板轮播代码块表格弹出框步骤折叠面板描述列表图示应用外壳页头树视图时间线图片预览调整手柄可调整大小的框滚动区域徽标进度指示器计量条数字滚动器加载指示器消息条(Snackbar)工具提示键盘快捷键标签(Tag)行内代码提示块(Callout)头像空状态标签组(Tag group)骨架屏文件项色块跑马灯文本标签页标签页视图应用栏导航栏导航抽屉搜索链接分页上一页/下一页链接步骤条面包屑目录链接卡片FAB 菜单状态Tanrei 是如何构建的参与贡献许可与致谢
首页组件搜索

搜索

一个搜索栏,或者代替它的紧凑触发器,在用户输入时提供建议和结果,视图可以停靠在搜索栏下方、以对话框打开或覆盖整个屏幕。

content_copy以 Markdown 格式查看
类别
导航
令牌
comp.search
层级
功能
构成自
Modal layer

概览

Web
tanrei-search
schedule
SwiftUI
TanreiSearch
schedule
Jetpack Compose
TanreiSearch
schedule
Flutter
TanreiSearch
schedule
React Native
Search
schedule

生成自 docs/status/status.json, specs/search.spec.json

规格已修订,尚未覆盖所有平台

本页描述的是规格当前所定的搜索,它也能用作站内搜索:代替搜索栏的触发器、对话框视图、作为链接的结果、状态行和快捷键。Web 组件已经实现了这一切,页面上的演示也是如此。SwiftUI、Compose、Flutter 和 React Native 在上方标记为“待跟进”:在跟上之前,它们提供的是上一版,即带输入框的搜索栏、停靠视图和全屏视图,以及建议;它们的示例展示的也是上一版。

空的、有查询词的,以及带图标按钮的

menumicaccount_circle

站内搜索:带快捷键的按钮触发器、图标触发器,以及显示快捷键的搜索栏。按下触发器即可打开它的视图

查询词行下方的建议,以及行内补全。输入“发票”,再用方向键移动试试

用法

搜索由一个搜索栏和一个视图组成。搜索栏里有搜索图标、输入框、有查询词时出现的清除按钮,末尾还可以放最多两个你自己的图标按钮,例如语音输入或账户。你自己的菜单按钮或返回按钮可以放进 leading 插槽,取代搜索图标。视图在用户搜索时打开,从上到下依次是建议、状态行、结果,然后是你自己的任何内容。

搜索栏还是触发器。 bar 决定放置搜索的位置上显示什么:

  • field(默认):带输入框的搜索栏。
  • button:外形与搜索栏相同的触发器,其中没有输入框,只有搜索图标、占位符和快捷键提示。用于有空间的页眉。
  • icon:纯图标按钮,显示搜索图标。用于没有空间的页眉。

触发器打开的是模态视图,即对话框或全屏视图,输入框位于该视图的页眉中。同一个产品可以在宽窗口上使用 button,在窄窗口上使用 icon。

三种呈现方式。 presentation 决定视图在哪里打开:

  • docked(默认):紧贴搜索栏下方、与它等宽的一个表面,位于平台的浮层中,就像菜单在锚点下方打开一样。焦点留在搜索栏的输入框中,所以建议变化时用户可以继续输入。下方空间不够时,视图在搜索栏上方打开。
  • dialog:靠近窗口顶部的一个模态表面,位于遮罩之上,页眉中有返回按钮、输入框和清除按钮。它适用于大窗口,由触发器打开。在遮罩上按下会关闭它。
  • full-screen:覆盖整个窗口的模态视图,页眉相同。它取得焦点并留住焦点,关闭时把焦点交还给搜索栏或触发器。

大窗口上使用停靠视图或对话框,小窗口上使用全屏视图。搜索不会替你做选择:请根据你自己的断点来设置 presentation。触发器配 docked 时打开的是对话框,因为停靠视图没有自己的输入框,这种情况会在调试构建中报告。

建议是一种项,表示用户可能想搜的查询词,例如过去搜过的词,或者对已输入文字的补全。每条建议有 value 和 headline,还可以有 supportingText 和 leadingIcon,例如用历史图标表示过去的查询词。当前查询词对应的建议由你提供;搜索只负责绘制,不做筛选。以查询词开头的建议,会像网页搜索那样把它补上的部分画得更粗。选择一条建议会触发带有其值的 select。搜索自己从不更改查询词,所以选择意味着什么由你决定:通常是把这条建议填进搜索栏并搜索。

查询词行。 显示建议时,第一行就是按原样输入的查询词:搜索图标加上查询词,如果你提供了 queryRowText,它显示在下方(例如“搜索全部邮件”)。这一行从建议出现起就是活动行,所以 Enter 总是搜索用户输入的内容,就像浏览器地址栏的第一行一样;按下方向键进入各条建议。这一行不需要任何文字:图标和查询词本身就是完整的一行。另一种常见形式是网页搜索页面的做法:把 queryRow 设为 none,就没有这一行,在用户移动之前没有任何项处于活动状态,在此之前 Enter 搜索用户输入的内容。

在各行之间移动。 方向键依次经过查询词行、各条建议,然后是各个结果。移到某条建议时,它会显示在输入框中,但查询词不变,所以 Enter 选中的就是输入框里看到的内容;回到查询词行时,按原样输入的查询词又回来了。到了两端会循环:在最后一行按下方向键回到第一行,在第一行按上方向键到最后一行。要让方向键停在两端,把 wrap 设为 false。

行内补全。 设置 inlineCompletion 后,搜索会像地址栏一样,用第一条以查询词开头的建议在输入框中补全查询词,补上的部分在光标之后以选中状态显示。移动光标即接受补全,Backspace 取消补全,Enter 接受补全并搜索。删除或粘贴之后、输入法组合文字期间以及使用屏幕键盘时都不会补全。默认关闭。

结果是第二种项,表示搜索找到的东西:一个页面、一个章节、一条消息。结果有 value、headline、excerpt,还可以有 leadingIcon,并且它通往某个地方:有 href 时,它的行是真正的链接,平台像打开任何链接那样打开它,例如按住修饰键在新标签页中打开,并带有链接自己的上下文菜单。没有 href 时,行是一个按钮,select 是唯一的信号。结果组把若干结果放在同一个标题之下:可以是“消息”这样低调的标题,也可以给组自己一个 href,让标题成为这些结果(各个章节)所属的页面。摘录是一段文字,由你在其中标出匹配的部分;搜索不会在文本中查找查询词。在 Web 上,摘录是元素自身的内容,匹配的部分用 <mark> 包起来;也可以用 excerpt 传入若干文本片段,其中每隔一个是匹配的部分。

状态。 搜索从不执行查询、等待或筛选:每次更改它都触发 input,并绘制你给它的内容。请用 status(idle、loading 或 error)和 statusText 告诉它你的搜索正在做什么:结果数量(“‘令牌’共 12 条结果”)、没有找到任何内容,或者失败的情况。状态行显示这段文本,并在文本变化时朗读它;加载期间,它会在短暂延迟后显示加载指示器。

快捷键。 shortcut 指定打开搜索的按键,使用键盘快捷键的键名(mod+k、/)。搜索把它们写成一条提示,也就是一行与用户键盘相符的文本:显示在按钮触发器的末尾,以及搜索栏为空且没有焦点的时候。搜索还把它们作为触发器或输入框的键盘快捷键暴露出来。只有在你绑定了这些按键,或设置了 bindShortcut 时,按键才会生效:设置之后,只要搜索处于显示且启用的状态,它就在整个窗口中监听,按下这些键时打开,再按一次时关闭。

打开和关闭。 在搜索栏上按下、输入字符,或在输入框中按下方向键,都会打开视图。仅仅获得焦点绝不会打开它:用 Tab 移到搜索栏上,或焦点从全屏视图返回时,视图都保持关闭。搜索用 toggle 请求打开或关闭,其中带有新的状态,关闭时还带有原因:escape、back、select、submit、outside、tab、focus-out 或 shortcut。视图关闭时,查询词保持原样。显示建议时,在查询词行上按 Enter,会以按原样输入的查询词触发 submit;没有建议而有结果时,Enter 打开的是第一个结果,与文档搜索一样。submit 之后,如果视图正在显示结果或状态,它会保持打开,让用户可以继续前往这些内容。在 Web 上,元素自己设置 expanded;在 SwiftUI 和 Flutter 上,改变的是绑定或控制器。在 Compose 和 React Native 上,与菜单一样,由你在回调中设置 expanded。

<tanrei-search name="q" label="搜索邮件" placeholder="搜索邮件" clear-label="清除搜索内容" query-row-text="搜索全部邮件">
  <tanrei-button variant="text" slot="trailing" label="语音搜索"><span slot="icon">mic</span></tanrei-button>
  <tanrei-search-suggestion value="invoices" headline="发票" leading-icon="history"></tanrei-search-suggestion>
  <tanrei-search-suggestion value="folder:invoices" headline="发票"
    supporting-text="文件夹 · 24 条消息" leading-icon="folder"></tanrei-search-suggestion>
  <!-- 其他子元素是你自己放在视图中的内容,位于建议之后。 -->
</tanrei-search>

<!-- 网页搜索页面的形式:没有查询词行,用户移动之前没有活动项;方向键停在两端。 -->
<tanrei-search label="搜索网页" placeholder="搜索" query-row="none" no-wrap></tanrei-search>

<!-- 地址栏的形式:用第一条以查询词开头的建议在输入框中补全查询词。 -->
<tanrei-search label="搜索或输入网址" inline-completion></tanrei-search>

<!-- 在小窗口上:视图覆盖整个窗口,并带有返回按钮。 -->
<tanrei-search presentation="full-screen" label="搜索邮件" placeholder="搜索邮件"
  clear-label="清除搜索内容" back-label="返回"></tanrei-search>

<!-- 站内搜索:带快捷键的触发器、对话框视图,以及作为链接的结果。 -->
<tanrei-search id="docs-search" bar="button" presentation="dialog" label="搜索文档" placeholder="搜索"
  shortcut="mod+k" bind-shortcut clear-label="清除搜索内容" back-label="返回">
  <!-- 带 href 的组就是页面;它的结果是在这个页面中找到的章节。 -->
  <tanrei-search-result-group value="/tokens/" headline="设计令牌" href="/tokens/" leading-icon="article">
    颜色、尺寸和动效都是<mark>令牌</mark>,分为三层。
    <tanrei-search-result value="/tokens/#layers" headline="层" href="/tokens/#layers" leading-icon="tag">
      层可以更改<mark>令牌</mark>的值,也可以添加自己的令牌。
    </tanrei-search-result>
  </tanrei-search-result-group>
  <!-- 其他子元素是你自己的内容,位于结果之后。 -->
  <tanrei-button variant="text">加载更多结果</tanrei-button>
</tanrei-search>

<script type="module">
  import '@tanrei/web/components/search';
  import '@tanrei/web/components/button';
  const search = document.querySelector('[name="q"]');
  search.addEventListener('input', () => showSuggestionsFor(search.value));
  search.addEventListener('submit', () => runSearch(search.value)); // 可取消;在表单内,它随后会提交表单
  search.addEventListener('select', (e) => openSuggestion(e.detail.value));
  // 元素先设置自己的 expanded,再触发 toggle。
  search.addEventListener('toggle', (e) => log(e.detail.expanded, e.detail.reason));

  // 搜索从不查询、等待或防抖:这些都由你来做。
  const docs = document.querySelector('#docs-search');
  let asked = 0;
  docs.addEventListener('input', async () => {
    const mine = ++asked;
    docs.status = 'loading';
    docs.statusText = '正在搜索';
    const found = await query(docs.value);
    if (mine !== asked) return; // 已经提出了更新的问题:丢弃这个答案
    show(found); // 替换 <tanrei-search-result> 子元素
    docs.status = 'idle';
    docs.statusText = `“${docs.value}”共 ${found.length} 条结果`; // 每个答案只设置一次:它会被朗读
  });
  // 某个结果被就地激活。取消这个事件,就把链接交给你的路由。
  docs.addEventListener('select', (e) => { /* e.preventDefault(); router.push(e.detail.value); */ });
</script>
import { Button, Search, SearchResult, SearchResultGroup, SearchSuggestion } from '@tanrei/react';

<Search
  label="搜索邮件"
  placeholder="搜索邮件"
  clearLabel="清除搜索内容"
  value={query}
  onInput={(e) => setQuery(e.currentTarget.value)}
  onSubmit={() => runSearch(query)}
  onSelect={(e) => openSuggestion(e.detail.value)}
>
  <Button variant="text" slot="trailing" label="语音搜索" onClick={dictate}><span slot="icon">mic</span></Button>
  {suggestions.map((s) => (
    <SearchSuggestion key={s.value} value={s.value} headline={s.headline} supportingText={s.detail} leadingIcon={s.icon} />
  ))}
</Search>

// 站内搜索:带快捷键的触发器、对话框视图,以及作为链接的结果。
// excerpt 是若干文本片段:每隔一个是匹配的部分。
<Search
  bar="button"
  presentation="dialog"
  label="搜索文档"
  placeholder="搜索"
  shortcut={['mod+k']}
  bindShortcut
  clearLabel="清除搜索内容"
  backLabel="返回"
  status={status}
  statusText={statusText}
  onInput={(e) => runQuery(e.currentTarget.value)}
  onSelect={(e) => { e.preventDefault(); router.push(e.detail.value); }}
>
  {pages.map((page) => (
    <SearchResultGroup key={page.url} value={page.url} headline={page.title} href={page.url} leadingIcon="article" excerpt={page.excerpt}>
      {page.sections.map((s) => (
        <SearchResult key={s.url} value={s.url} headline={s.title} href={s.url} leadingIcon="tag" excerpt={s.excerpt} />
      ))}
    </SearchResultGroup>
  ))}
</Search>
import Tanrei

// 每次编辑都会写入 text;打开和关闭会写入 isExpanded。
TanreiSearch("搜索邮件", text: $query, isExpanded: $isSearching,
             prompt: Text("搜索邮件"), clearLabel: "清除搜索内容",
             onSubmit: { value in runSearch(value) },
             onSelect: { value in openSuggestion(value) }) {
    TanreiSearchSuggestion("发票", leadingIcon: "history", value: "invoices")
    TanreiSearchSuggestion("发票", supportingText: "文件夹 · 24 条消息", leadingIcon: "folder", value: "folder:invoices")
}
import io.github.chnotchy.tanrei.components.TanreiSearch
import io.github.chnotchy.tanrei.components.TanreiSearchSuggestion

// 状态提升:value 和 expanded 由你保存,并在回调中更新。
TanreiSearch(
    value = query,
    onValueChange = { query = it },
    expanded = expanded,
    onExpandedChange = { open, _ -> expanded = open }, // 第二个参数是原因
    label = "搜索邮件",
    placeholder = "搜索邮件",
    clearLabel = "清除搜索内容",
    onSearch = { runSearch(query) },
    onSelect = { openSuggestion(it) },
) {
    TanreiSearchSuggestion(value = "invoices", headline = "发票", leadingIcon = "history")
    TanreiSearchSuggestion(value = "folder:invoices", headline = "发票", supportingText = "文件夹 · 24 条消息", leadingIcon = "folder")
}
import 'package:tanrei/tanrei.dart';

// TanreiSearchController 是一个同时保存 isExpanded 的 TextEditingController。
final TanreiSearchController search = TanreiSearchController();

TanreiSearch(
  controller: search,
  semanticLabel: '搜索邮件',
  hintText: '搜索邮件',
  clearLabel: '清除搜索内容',
  onChanged: showSuggestionsFor,
  onSubmitted: runSearch,
  onSelected: openSuggestion,
  suggestions: const <TanreiSearchSuggestion>[
    TanreiSearchSuggestion(value: 'invoices', headline: '发票', leadingIcon: 'history'),
    TanreiSearchSuggestion(value: 'folder:invoices', headline: '发票', supportingText: '文件夹 · 24 条消息', leadingIcon: 'folder'),
  ],
);
import { Search } from '@tanrei/react-native';

// 受控:由你在 onChangeText 和 onExpandedChange 中更新 value 和 expanded。
<Search
  value={query}
  onChangeText={setQuery}
  expanded={expanded}
  onExpandedChange={(next) => setExpanded(next)}
  accessibilityLabel="搜索邮件"
  placeholder="搜索邮件"
  clearLabel="清除搜索内容"
  onSubmitEditing={() => runSearch(query)}
  onSelect={openSuggestion}
  suggestions={[
    { value: 'invoices', headline: '发票', leadingIcon: 'history' },
    { value: 'folder:invoices', headline: '发票', supportingText: '文件夹 · 24 条消息', leadingIcon: 'folder' },
  ]}
/>

// 在小窗口上:presentation="full-screen" 和 backLabel="返回"。Android 的返回按钮会关闭视图。

规格

停靠视图,其中有一条建议、状态行和分组的结果,就地绘制

禁用的,以及打开的停靠视图

构成

属性

属性 类型 默认值 说明
presentation docked | dialog | full-screen "docked" Where the view opens: docked under the bar, without taking focus from it; dialog, a modal surface near the top of the window with its own header (a large screen, opened from a trigger); or full-screen, over the whole window with its own header (a small screen). One product uses more than one and switches by window size.
bar field | button | icon "field" What stands where the search is placed. field: the bar with its input, as before. button: a trigger shaped like the bar that holds no input — the search glyph, the placeholder and the shortcut hint — for an app bar with room. icon: an icon-only Button showing the search glyph, for an app bar without. A trigger opens a modal view (dialog or full-screen), where the input is. One product uses button on a wide window and icon on a narrow one.
value string "" The query.
label string "" Names the search field, the trigger, the view, the suggestions and the results for assistive technology ("Search mail"). Drawn only as a button trigger's text while placeholder is empty. Required.
placeholder string "" A hint shown while the value is empty, and the text of a button trigger. Never a replacement for label.
expanded boolean false Whether the view is open. The search asks to open and close it with toggle (SRC-5, SRC-6, SRC-36, SRC-38).
disabled boolean false Prevents focus, editing and opening the view.
clearLabel string "" The clear button's accessible name, in the product's language ("Clear search"). Required while the clear button can show.
backLabel string "" The accessible name of the back button in a modal view's header ("Back"). Required for full-screen and for dialog.
shortcut strings The keyboard shortcut that opens the search, in the keyboard shortcut component's key names: one chord per string, pressed in order (["mod+k"], ["/"]). The search writes it as a hint, a line of text with no keycaps (SRC-37), and exposes it as the keyboard shortcut of its trigger or input. It makes the keys work only while bindShortcut is true (SRC-38); otherwise the product binds them.
bindShortcut boolean false Makes the search itself listen for shortcut, anywhere in the window, for as long as it is shown and enabled: the keys open it, and close it again while it is open (SRC-38). Off by default: a component listens outside itself only where the product asks it to.
status idle | loading | error "idle" What the product's search is doing, which the product sets: idle (nothing is awaited: results, or none, are final), loading (a query is running: the status row shows a loading indicator after its delay) or error (the query failed: statusText is drawn as an error and announced at once). The search never runs a query itself (SRC-51).
statusText string "" The status row's text, in the product's language, announced to assistive technology when it changes: the count ("12 results for tokens"), that nothing was found ("No results for tokne"), the failure ("Search is unavailable"); while loading, the loading indicator's name ("Searching"). Empty draws no status row unless status is loading.
queryRow first | none "first" Where the query as typed stands among the suggestions, which are queries. first: a row of its own above them — the search glyph and the value, with queryRowText under it — drawn while the view shows suggestions and the value is not empty, and active from the moment they show, so that the action key always searches for what was typed, as the first row of a browser's address bar does (SRC-57). none: no such row: no suggestion is active until the person moves to one, so that the action key searches for what was typed until then, as a web search page does, and the input itself is the place before the first suggestion in the arrow keys' cycle (SRC-14).
queryRowText string "" What the query row says beside the query, in the product's language, drawn as its supporting text and read as its description ("Search all mail", "Ask the assistant"). Empty draws the search glyph and the query alone: the row needs no words. Ignored while queryRow is none.
inlineCompletion boolean false Completes the query in the input while the person types, from the first suggestion whose headline begins with it: the rest of that headline is written after the caret, selected, and the query row shows the completed query (SRC-55). A completion of the beginning only; never after a deletion or a paste, during an input-method composition or on an on-screen keyboard; moving the caret accepts it, Backspace takes it away. Off by default: an address bar completes, a search page does not. Ignored while queryRow is none.
wrap boolean true Whether the arrow keys go round at the ends of the view's rows: Down Arrow on the last to the first, Up Arrow on the first to the last — with queryRow none, through the input's own place before the first suggestion (SRC-14, SRC-49). False stops them at the ends.
iconSpace auto | always | never "auto" Whether a row of the view — a suggestion, a result, a result group's linked heading — keeps the room of the leading icon column where it has no icon, so that the headlines of the view start on one line. auto: every row keeps the column while any suggestion or result of the view has a leading icon, and none while none has. always: every row keeps it. never: only a row that has an icon has the column. The view is decided as a whole. The menu's iconSpace, with the same values and default (SRC-52).
density regular | compact "regular" How much room a row of the view takes — a suggestion, a result, a result group's linked heading —: its least height, its paddings, the gap after its icon column and the size of its glyph, and never its text style. regular (a 56 row in the default system) is for a product used by touch as well as by pointer; compact (a 32 row with a 20 glyph, the tree view's compact row) is for a tool used with a pointer, a command palette looked through with the keyboard. For touch a row is never lower than the touch target in either (SRC-16). The bar, the trigger and the view's header are not changed. A design system may add values.

插槽

插槽 说明
leading An icon-only Button at the bar's start (a menu or back button), drawn in place of the search glyph.
trailing Up to two icon-only Buttons at the bar's end, after the clear button (voice input, account).
default The product's own content in the view, after the suggestions, the status row and the results: a button that loads more results, a link to the full results page, or richer content for an empty query.

事件

事件 说明
input The person changed the value (typing, deleting, pasting, dictating, the clear button, Escape); carries the new value. Not emitted when the product sets value. It is the product's cue to run its query; the search does not delay or drop it (SRC-51).
submit The person pressed the keyboard's action key (Enter, Search) with no suggestion active and no result current; carries the value.
select The person chose a suggestion, or activated a result in place (without a modifier key, in the same window); carries its value. For a result with an href it is emitted before the platform follows the link, and on the web cancelling it keeps the link from being followed, so that a router can take it.
toggle The search asks to open or close its view; carries the new expanded value and, when closing, the reason: escape, back, select, submit, outside, tab, focus-out or shortcut (in the platform's casing).

条目

该组件重复排列的条目种类。测试样例按顺序列出条目;各平台以各自的惯用方式为每个种类命名。

suggestion

A choice that completes or replaces the query while the person types: a query they searched before, or a completion. Choosing it emits select and the product sets the value. A thing the product opens is a result.

属性 类型 默认值 说明
value string "" Identifies the suggestion; select carries it. Unique among the suggestions.
headline string "" The suggestion's text, and its accessible name.
supportingText string "" A second line under the headline ("Folder · 24 messages"), and its description.
leadingIcon string "" The name of a glyph at the row's start (history for a past query, a folder for a result). Empty draws none.
规格 Web SwiftUI Jetpack Compose Flutter React Native
条目 tanrei-search-suggestion TanreiSearchSuggestion TanreiSearchSuggestion TanreiSearchSuggestion SearchSuggestion
value · 属性 value value value value value
headline · 属性 headline headline headline headline headline
supportingText · 属性 supportingText supportingText supportingText supportingText supportingText
leadingIcon · 属性 leadingIcon leadingIcon leadingIcon leadingIcon leadingIcon
备注 A child element with value, headline, supporting-text and leading-icon attributes, as <option> in a <datalist>. TanreiSearchSuggestion(_ headline:, supportingText:, leadingIcon:, value:) in the suggestions view builder. TanreiSearchSuggestion(value, headline, supportingText, leadingIcon) called in the search's content lambda, before the product's own content. TanreiSearchSuggestion(value:, headline:, supportingText:, leadingIcon:) in the search's suggestions: list. The element type of the suggestions array: { value, headline, supportingText?, leadingIcon? }.

result

A thing the search found that the person can go to: a page, a section of a page, a message, a file. It is a link, not an option.

属性 类型 默认值 说明
value string "" Identifies the result; select carries it. Unique among the suggestions, results and result groups.
headline string "" The result's title, and its accessible name.
excerpt strings A passage of the thing found, as runs of text in order: the first, third, fifth… run is plain text and the second, fourth… is a match, drawn marked (SRC-43). ["Tokens are ", "design", " decisions"] marks design; a passage that begins with a match begins with an empty run; one run alone is a passage without marks. The product's search decides what matched; the search component does not look for the query in the text.
leadingIcon string "" The name of a glyph at the row's start (article for a page, tag for a section). Empty draws none.
href string "" Where the result goes: an address as the platform's links take one (a URL; on the web a path or a fragment as well), in the prop set every control with a destination takes. Not empty, it makes the row a link, opened by the platform as its own links are (SRC-45). Empty makes the row a button: select is then the only signal, and the product opens the thing.
target same | new "same" Where the destination opens. same: where the person is. new: a new context — a new tab or window on the web, outside the current screen elsewhere — which targetLabel says. Ignored without href.
targetLabel string "" What assistive technology reads after the result's name while target is new ("opens in a new tab"), in the product's language. Required while target is new; ignored otherwise.
规格 Web SwiftUI Jetpack Compose Flutter React Native
条目 tanrei-search-result TanreiSearchResult TanreiSearchResult TanreiSearchResult SearchResult
value · 属性 value value value value value
headline · 属性 headline headline headline headline headline
excerpt · 属性 excerpt excerpt excerpt excerpt excerpt
leadingIcon · 属性 leadingIcon leadingIcon leadingIcon leadingIcon leadingIcon
href · 属性 href destination href href href
target · 属性 target target target target target
targetLabel · 属性 targetLabel targetLabel targetLabel targetLabel targetLabel
备注 A child element whose link is an <a href> (a <button> without href) it keeps as its own first child in the light DOM, drawn as nothing and slotted over the row it draws in its shadow root, so that the search's input can name it as its active descendant (SRC-50); a page's rules for anchors and buttons neither move nor paint it. The excerpt is its child content: text with <mark> elements for the matches, which is what search engines hand back, styled through ::slotted(mark); the excerpt property (an array of runs) is used while it has no child content. Inserting an engine's HTML is the product's act: the element never parses a string as markup. rel and download are forwarded to the anchor, as every link form forwards them; target="new" is target="_blank" with noopener in rel. Not built on this platform yet. TanreiSearchResult(_ headline:, excerpt: [String], leadingIcon:, value:, destination: URL?); with a destination it opens through the environment's openURL and has the .isLink trait. target and targetLabel as the platform's link forms map them. Not built on this platform yet. TanreiSearchResult(value, headline, excerpt: List<String>, leadingIcon, href); with an href it opens through LocalUriHandler. target and targetLabel as the platform's link forms map them. Not built on this platform yet. TanreiSearchResult(value:, headline:, excerpt: [...], leadingIcon:, href: Uri?, target:, targetSemanticLabel:) in the search's results: list, with Semantics(link: true). Not built on this platform yet. An element type of the results array: { value, headline, excerpt?, leadingIcon?, href? }, with accessibilityRole="link"; an href opens through Linking. target and targetLabel as the platform's link forms map them.

result-group · 分组 — 包含条目

Results that belong together, under one heading: the sections found in one page, or the results of one kind. With an href its heading is itself a result (the page), and its results are drawn under it as its parts; without one its heading is a title.

属性 类型 默认值 说明
headline string "" The group's heading: the page's title, or the name of the kind ("Pages"). It names the group for assistive technology.
value string "" Identifies the heading as a result while href is not empty; select carries it.
excerpt strings While href is not empty, the heading's own excerpt, in the runs a result's excerpt has. Ignored without href.
leadingIcon string "" While href is not empty, the name of a glyph at the heading row's start. Ignored without href.
href string "" Where the heading goes. With it the heading is a result's row and a link (SRC-44, SRC-45); empty makes it a title that takes no input.
target same | new "same" Where the destination opens. same: where the person is. new: a new context — a new tab or window on the web, outside the current screen elsewhere — which targetLabel says. Ignored without href.
targetLabel string "" What assistive technology reads after the result's name while target is new ("opens in a new tab"), in the product's language. Required while target is new; ignored otherwise.
规格 Web SwiftUI Jetpack Compose Flutter React Native
条目 tanrei-search-result-group TanreiSearchResultGroup TanreiSearchResultGroup TanreiSearchResultGroup SearchResultGroup
headline · 属性 headline headline headline headline headline
value · 属性 value value value value value
excerpt · 属性 excerpt excerpt excerpt excerpt excerpt
leadingIcon · 属性 leadingIcon leadingIcon leadingIcon leadingIcon leadingIcon
href · 属性 href destination href href href
target · 属性 target target target target target
targetLabel · 属性 targetLabel targetLabel targetLabel targetLabel targetLabel
备注 A child element holding <tanrei-search-result> children; with href its own heading's link is an <a> it keeps as its own child, as a result does, and its excerpt is the content of its excerpt slot, with <mark> as in a result. Not built on this platform yet. TanreiSearchResultGroup(_ headline:, destination:, …) { results }. Not built on this platform yet. TanreiSearchResultGroup(headline, href, …) { results }. Not built on this platform yet. TanreiSearchResultGroup(headline:, href:, results: [...]). Not built on this platform yet. The other element type of results: { headline, href?, …, results: [...] }.

状态

行为

以 EARS 形式写成的需求。每个平台的实现都按这些 ID 逐条测试。需求原文取自规格文件,原样以英文呈现。

ID 需求
SRC-1 THE search SHALL draw its bar as wide as its layout gives it and at least comp.search.container.height high, filled with comp.search.standard.container.color, raised by comp.search.standard.container.elevation and rounded by comp.search.container.shape, and SHALL lay out in one row, each element vertically centered and comp.search.container.gap from the next, except that its action buttons — the clear button and the icon-only Buttons of the trailing slot — stand comp.search.container.button-gap from one another (SRC-34): the search glyph comp.search.container.padding-inline from the start edge (or, WHILE the leading slot is filled, the product's icon-only Button comp.search.container.padding-inline-with-button from it, in place of the glyph), the input taking the remaining width, the clear button WHILE it is shown (SRC-10), and the icon-only Buttons of the trailing slot; the last element SHALL end comp.search.container.padding-inline-with-button from the end edge when it is an icon-only Button, and comp.search.container.padding-inline when it is the input. Right-to-left layouts SHALL mirror the row.
SRC-2 THE search SHALL draw the glyph search of the system's icon set at comp.search.leading-icon.size in comp.search.standard.leading-icon.color with the family and fill of an unselected icon, sys.icon.weight and an optical size clamped between sys.icon.optical-size.min and sys.icon.optical-size.max, SHALL NOT mirror it when the layout direction is right-to-left, and SHALL hide it from assistive technology. THE search SHALL draw no mark of its own (no path, shape or character of its own) for this glyph or for the glyphs of its clear and back buttons (SRC-10, SRC-11).
SRC-3 THE search SHALL draw the value on one line in comp.search.input.typescale and comp.search.standard.input.color, scrolling it sideways inside the input when it is longer, and WHILE the value is empty the placeholder in the same text style in comp.search.standard.placeholder.color; it SHALL draw the caret in comp.search.standard.caret.color and highlight selected text in comp.input-box.selection.color, drawing it in comp.input-box.selection.content.color: the product's one selection pair for text entry.
SRC-4 THE search SHALL edit its value in the platform's native text element and SHALL follow the text field's rules for it: TXI-1 (input once per change, and none when the product sets value), TXI-4 (input-method composition), TXI-20 for the search type (a general keyboard whose action key reads as search) and TXI-24 (the typed text's own direction); it SHALL hide a clear or cancel button that the platform draws inside its native element (the web's search cancel button), because it draws its own (SRC-10).
SRC-5 WHILE collapsed and bar is field, WHEN the person presses the bar outside its slot elements and the clear button, types into the input, or presses Down Arrow in it, THE search SHALL focus the input and emit toggle once with expanded true; focus that reaches the input by Tab, or returns to it when the view closes, SHALL NOT expand it. The Down Arrow that opens the view SHALL only open it: the row the action key takes is then the one SRC-14 and SRC-49 make current as the view opens, made current by an arrow key and so announced at once (SRC-24). THE search SHALL become expanded through its binding or controller where expanded is one (SwiftUI, Flutter) and by setting its own property on the web, and by the product setting expanded to true on Compose and React Native. WHILE bar is button or icon the trigger's activation is what expands the search (SRC-36), and the product's shortcut where the search binds it (SRC-38).
SRC-6 WHILE expanded, WHEN the person presses Escape or the platform's back, activates the back button (SRC-11), chooses a suggestion (SRC-15), activates a result in place (SRC-45), submits where submitting closes (SRC-13) or presses the shortcut the search binds (SRC-38), or, WHILE presentation is dialog, presses the scrim (a modal view answers Escape, back and the scrim as its modal layer does, MDL-6), or, WHILE presentation is docked, presses outside the bar and the view, presses Tab or Shift+Tab, or moves focus out of the search, THE search SHALL emit toggle once with expanded false and that reason (escape, back, select, submit, shortcut, outside, tab or focus-out) and SHALL be collapsed as SRC-5 says it is expanded; the value SHALL stay as it is. Tab and Shift+Tab SHALL then move focus on from the input as they would have, and whether a press outside also reaches the element under it SHALL follow the platform and be stated in its README, as for the menu (MNU-5). Focus that moves between the bar's input and a result of the docked view (SRC-49) has not left the search.
SRC-7 WHILE expanded, presentation is docked and bar is field and the view has content (a suggestion, a status row, a result, a result group, or content in the default slot), THE search SHALL present the view in the platform's overlay layer, the one the menu's surface uses (MNU-1), comp.search.view.offset below the bar, as wide as the bar and aligned with it; WHERE the room below, within comp.search.view.viewport-margin of the viewport's edge and of the on-screen keyboard, is less than the view needs and the room above is more, it SHALL place the view above the bar instead; it SHALL limit the view's height to the room left and scroll its content beyond it, and keep following the bar while it moves. It SHALL fill the view with comp.search.view.container.color, raise it by comp.search.view.container.elevation, round it by comp.search.view.container.shape, clip the content to that shape and inset it by comp.search.view.padding-block and comp.search.view.padding-inline. WHILE the view has no content THE search SHALL draw no view and stay expanded.
SRC-8 WHILE presentation is docked THE search SHALL keep focus in the bar's input while the view is open, because the view is an operated overlay whose focus is the input it belongs to: it SHALL NOT move focus into the view when it opens, trap focus, make anything inert or draw a scrim; a press on a suggestion, on the status row or on the view's surface SHALL NOT take focus from the input; a result is a link and takes focus when the person presses it or reaches it by Down Arrow (SRC-49), which is still focus inside the search; and the search SHALL leave focus where the person put it when the view closes.
SRC-9 WHEN expanded becomes true WHILE presentation is full-screen THE search SHALL present the view over the whole window as a modal overlay on its modal layer without the layer's scrim (MDL-1 WHILE scrim is false, the view filling the window), filled with comp.search.view.container.color to every edge of the window and under every system inset, with its content inside the safe area and above the on-screen keyboard: at its top a header at least comp.search.header.height high holding the back button (SRC-11) comp.search.header.padding-inline from the start edge, the input with the same value, and the clear button WHILE it is shown, the last of them comp.search.header.padding-inline from the end edge, comp.search.container.gap apart and vertically centered; under the header a line of comp.search.divider.thickness in comp.search.divider.color across the window; under that the view's content in the order SRC-46 gives, scrolling. It SHALL move focus to the header's input with the caret at the end of the value, keep focus inside the view, and make everything outside it inert and hidden from assistive technology, as its modal layer does (MDL-2, MDL-4); WHEN the view closes THE search SHALL return focus to the bar's input without expanding it again (SRC-5), or to the trigger WHILE bar is button or icon.
SRC-10 WHILE value is not empty and disabled is false THE search SHALL show a clear button: an icon-only Tanrei Button of the text variant showing the glyph close of the system's icon set, not mirrored, named by clearLabel, of size small in the bar and medium in the full-screen header. WHEN it is activated THE search SHALL set value to empty, emit input once with the empty value and move focus to the input it belongs to, and SHALL NOT expand or collapse. WHILE clearLabel is empty THE search SHALL still show the button, and in debug builds report that it has no accessible name.
SRC-11 WHILE the full-screen view is open THE search SHALL draw a back button at the start of its header: an icon-only Tanrei Button of the text variant and the medium size showing the glyph arrow_back of the system's icon set, mirrored in right-to-left layouts by the icon helper, as the icon set marks it (SRC-32), named by backLabel; WHEN it is activated THE search SHALL collapse with the reason back (SRC-6). WHILE backLabel is empty THE search SHALL still draw it, and in debug builds report that it has no accessible name.
SRC-12 WHILE collapsed and the input has focus, WHEN the person presses Escape with a value that is not empty THE search SHALL set value to empty and emit input once, as a native search input does; with an empty value Escape SHALL do nothing and pass on to the enclosing element.
SRC-13 WHEN the person presses the keyboard's action key (Enter, Search, Go) in the input while the query row is active or no row is (SRC-14, SRC-57), no result is current (SRC-49) and no input method is composing, or presses the query row by pointer or touch, THE search SHALL, WHILE an inline completion is shown, first accept it (SRC-55), and SHALL emit submit once with the value and then, WHILE expanded and the view shows no result, no result group and no status row, collapse with the reason submit (SRC-6), so that toggle follows submit; WHILE the view shows one of them it SHALL stay expanded, because what the person asked for is already in front of them, and the product closes the view where its submit goes elsewhere; on the web, inside a form, it SHALL then request the form's submission unless submit was cancelled, as a native input does. The submission SHALL be requested through the form's default button (BTN-30): WHILE the form has a submit button — the platform's own or a Button of type submit — the first of them in document order SHALL be pressed, so that its click is emitted and its name and value are sent, and WHILE that button is disabled nothing SHALL be submitted; only a form with no submit button is asked directly.
SRC-14 WHILE expanded and the view holds suggestions THE search SHALL keep focus in the input, so that typing goes on editing the value, and SHALL make at most one of its rows current without moving focus, as an editable combobox with list autocomplete does. The rows the arrow keys go through are, in this order: the query row WHILE it is drawn (queryRow first and a value that is not empty, SRC-57), and otherwise the input's own place, which stands for the value as typed and makes no row current; then the suggestions, in the product's order; then the results (SRC-49). WHEN the input has focus and the view comes to show suggestions — it opens with them, the product gives or replaces them, or focus comes back to the input — and WHEN the person types, deletes or pastes, THE search SHALL make the first of those places current automatically: the query row, active, or the input's place, no row being active — either way the action key searches for the value as typed (SRC-13). Down Arrow SHALL make the next row current and Up Arrow the previous one, Down Arrow from the input's place going to the first suggestion and Up Arrow on the first suggestion back to the input's place; WHILE wrap is true Down Arrow on the last row SHALL go to the first place and Up Arrow on the first place to the last row, and WHILE wrap is false they SHALL do nothing at the ends. WHEN a suggestion becomes active by an arrow key THE search SHALL show its headline in the input in place of the value, the caret at its end, without changing value or emitting input, so that the action key chooses what the input shows (SRC-15); WHEN the query row or the input's place becomes current again, or a result takes focus, THE search SHALL show the value as typed again (and its inline completion, SRC-55); WHEN the person types, deletes or pastes while a suggestion's headline is shown, that text, edited, SHALL become the value (input, SRC-4); and WHEN the view closes or the input loses focus without a choice THE search SHALL show the value as typed. Moving the caret SHALL leave the current row as it is, except that it accepts an inline completion (SRC-55). WHILE the person types on an on-screen keyboard THE search SHALL make no row current by itself — neither as the suggestions show nor as the person types — so that the keyboard's action key (Search, Go) submits the value as typed (SRC-13), as a search field on a phone does, and the person chooses a suggestion by touching it. The person types on an on-screen keyboard from the moment the input takes focus from a touch or a pen (or a touch or a pen presses the focused input), and no longer once they press Down Arrow, Up Arrow or a key that moves the caret — keys only a hardware keyboard has — or a mouse presses the input, which make the first place current as after typing: whether a device has a touch screen, or a coarse primary pointer, does not tell which keyboard is in use on a laptop with a touch screen or a tablet with a keyboard attached. WHILE no row is current because of an on-screen keyboard, Down Arrow SHALL make the first row current (the query row, or the first suggestion where the input's place comes first) and Up Arrow the last row WHILE wrap is true. WHILE an input method is composing no row SHALL be current and Enter, Escape and the arrow keys SHALL be the input method's (TXI-4), so that the Enter that confirms a conversion chooses nothing; WHEN the composition ends THE search SHALL make the first place current as after typing. WHILE the input does not have focus no row SHALL be current. WHEN a row becomes current while part of it is scrolled out of view THE search SHALL scroll it into view. Enter with an active suggestion SHALL choose it (SRC-15). A row made current automatically is announced once typing pauses, and one an arrow key moves to at once (SRC-24).
SRC-15 WHEN the person activates a suggestion (by pointer or touch, or by Enter while it is active) THE search SHALL emit select once with the suggestion's value and then collapse with the reason select (SRC-6), so that toggle follows select; it SHALL NOT change value itself: the product sets the value it wants, the suggestion's text for a query. The query row is not a suggestion: activating it submits the value (SRC-13, SRC-57).
SRC-16 THE search SHALL lay out each suggestion as one row, at least comp.search.suggestion.container.height.regular tall and at least sys.target.touch tall for touch input, in both densities, and for fine pointers at least sys.target.pointer tall WHILE density is regular and as tall as its density gives WHILE density is compact (SRC-53) (rows that touch cannot extend a hit area over each other): comp.search.suggestion.container.padding-inline.regular from each edge, the leading icon column as SRC-52 says, then the headline with the supporting text under it, comp.search.suggestion.container.gap.regular after the icon column, padded by comp.search.suggestion.container.padding-block.regular above and below. It SHALL draw the headline in comp.search.suggestion.headline.typescale and the supporting text in comp.search.suggestion.supporting-text.typescale, both wrapping and growing the row rather than being cut; the leading icon at comp.search.suggestion.leading-icon.size.regular with the family and fill of an unselected icon, sys.icon.weight and an optical size clamped between sys.icon.optical-size.min and sys.icon.optical-size.max; and the row's highlight rounded by comp.search.suggestion.container.shape. Right-to-left layouts SHALL mirror the row, and the whole row SHALL be the suggestion's hit area.
SRC-17 WHILE a suggestion — the query row included — is hovered, active or pressed THE search SHALL render its container, leading icon, headline, supporting text and opacity from the component tokens of its highest-precedence state, with precedence pressed over active over hovered and the active suggestion taking the focused tokens; WHEN a suggestion becomes active THE search SHALL show the focus ring inside its row without animation, whether an arrow key or the search made it active. A pointer over a suggestion SHALL NOT make it active.
SRC-18 WHILE the bar is hovered, focused or pressed THE search SHALL render its container, outline, outline width, glyph, input, placeholder, caret and opacity from the component tokens of the highest-precedence active state, with precedence pressed over focused over hovered; unlike a button, focus gained by pointer or touch SHALL select the focused state, because a field shows where typing will go however it was focused. THE search SHALL show the bar's focus by its focused outline, drawn inside the bar's edge, and SHALL NOT draw the focus ring around the bar; WHERE sys.behavior.focus-style is glow it SHALL also draw the glow around the bar while it is focused. WHEN colors or widths change between states THE search SHALL animate them over comp.search.motion.state-duration with comp.search.motion.state-easing, and at once where motion is reduced.
SRC-19 WHEN the bar is pressed by pointer or touch, or a suggestion by pointer, touch or Enter, THE search SHALL show that element's pressed state without delay and SHALL keep it visible for at least sys.motion.duration.press-hold, even when the press ends sooner.
SRC-20 WHILE pressed THE search SHALL answer as sys.behavior.pressed-feedback names: overlay applies the pressed tokens to the whole container at once; ripple grows the pressed state layer from the point of contact (from the center for keyboard activation); dim applies the pressed opacity to the whole control and draws no state layer; none draws no answer to the press. Under ripple and dim only the container color stays with the state under the press; outline, glyph, input, placeholder, caret, leading icon, headline, supporting text, opacity and shape still come from the pressed tokens. Under none every part stays with the state under the press. The ripple grows over comp.search.motion.feedback-duration with comp.search.motion.state-easing, fades over comp.search.motion.state-duration with comp.search.motion.state-easing once the press has ended and press-hold has passed, and appears whole where motion is reduced. The container is the bar for a press on the bar and the row for a press on a suggestion; the control a dim applies to is the bar or the row.
SRC-21 THE search SHALL ease its bar, view and suggestion corners by sys.shape.corner-smoothing (0 is a quarter circle, 0.6 the iOS continuous corner; a platform with only the OS curve draws it for any amount above 0) and show its keyboard focus as sys.behavior.focus-style names (ring or glow); a platform that cannot draw a choice SHALL fall back to the first value and state that in its README.
SRC-22 WHERE the bar is shorter than the minimum target THE search SHALL extend its hit area vertically to sys.target.touch for touch input and sys.target.pointer for fine pointers, without changing its visual size; a platform that cannot tell the input type SHALL use sys.target.touch.
SRC-23 WHEN the view opens THE search SHALL fade it in over comp.search.motion.open-duration with comp.search.motion.open-easing, a docked view also growing from its edge that faces the bar, and WHEN it closes SHALL fade it out over comp.search.motion.close-duration with comp.search.motion.close-easing; WHERE motion is reduced it SHALL appear and disappear at once. Focus SHALL move (SRC-9) when the view opens or closes, not when the motion ends.
SRC-24 THE search SHALL expose its input as a search field named by label and never by placeholder, with the platform's search role where it has one (a search box, the search-field trait, the search input type); WHILE the view shows suggestions, the web's input SHALL be a combobox with aria-autocomplete list (both WHILE an inline completion can be shown, SRC-55), aria-expanded true and aria-controls naming the suggestions' listbox. THE search SHALL announce the active row, as the input's active descendant on the web: at once WHEN an arrow key makes it active; and WHEN the search made it active automatically (the query row, SRC-14) only once it has stayed active for 500 milliseconds with nothing typed, each edit taking the active descendant away until then, as React Aria's autocomplete does, so that a screen reader reads the character typed first and then what the action key takes, and not a row after every key. The active option SHALL be selected (aria-selected true) and every other one not, from the moment it is active. THE search SHALL expose the suggestions on the web as a listbox named by label whose options — the query row first where it is drawn (SRC-57), then the suggestions — are named by their headline and described by their supporting text, and on the other platforms as buttons named and described the same way, with their position in the list; icons and the divider SHALL be hidden; WHILE the view shows no suggestion the web's input SHALL be a search box without the combobox role, whatever else the view holds; results SHALL never be options (SRC-50); the dialog and full-screen views SHALL each be exposed as their modal layer's modal dialog (MDL-10) named by label; the clear and back buttons SHALL be named by clearLabel and backLabel.
SRC-25 THE search SHALL NOT restyle the icon-only Buttons in its leading and trailing slots: each SHALL render from its own tokens and keep its own semantics and its own focus stop in reading order (the leading one before the input, the trailing ones after the clear button), and the search SHALL draw neither slot in the full-screen header. The hit areas of two neighbouring elements of the bar or the full-screen header SHALL stop at the middle of comp.search.container.gap, those of two neighbouring action buttons where the lengths SRC-34 keeps for them meet, and an icon-only Button's at the bar's edge. The gap, the length of SRC-34 and comp.search.container.padding-inline-with-button are what keep each icon-only Button's target whole: under the default system every icon-only Button of the bar and the header, the small clear button included, keeps a target at least sys.target.touch wide; a layer that narrows the gap or the padding narrows those targets.
SRC-26 WHILE disabled is true THE search SHALL NOT be focusable, editable or expandable, SHALL NOT emit input, submit, select or toggle, SHALL hide the clear button, SHALL expose the disabled state to assistive technology, and SHALL render the bar's container, outline, glyph, input, placeholder and opacity from the disabled component tokens; the slot icon-only Buttons keep their own state.
SRC-27 WHILE label is not empty THE search SHALL expose it as its accessible name, over a name the product gives it on the element (aria-label or aria-labelledby); WHILE label is empty and the product gives the search a name of its own on the element — aria-label, or aria-labelledby naming an element — THE search SHALL expose that name as its accessible name; WHILE label is empty and the product gives it none THE search SHALL still render, and in debug builds report that it has no accessible name; WHEN presentation, bar or status names a value the component does not define THE search SHALL render as docked, field or idle and in debug builds report the value; WHEN a result's headline is empty, or a result's or linked group heading's value is empty or repeats that of another suggestion, result or group, or a result group holds anything but results, THE search SHALL still render what it can and in debug builds report it; WHEN a suggestion's value is empty or repeats another's, or its headline is empty, THE search SHALL still render it and in debug builds report it; IF the trailing slot holds more than two elements THE search SHALL still lay them out and in debug builds report it.
SRC-28 WHILE the text size is enlarged THE search SHALL grow the bar and the full-screen header to hold one line of the input (their heights are minimums) and keep the value on one line, SHALL let suggestion rows grow and wrap, and SHALL NOT scale the icon-only Buttons it holds.
SRC-29 THE search SHALL hand the default slot's content comp.search.standard.suggestion.headline.color as the platform's inherited foreground (the web's inherited color, SwiftUI's foreground style, Compose's content color, Flutter's default text and icon style, React Native's Tanrei text context), inset by comp.search.suggestion.container.padding-inline.regular at the sides, and plain text given as that content, where the platform must style it, SHALL take sys.typescale.body.
SRC-30 IF the icon set cannot draw a glyph of the search yet (search, close or arrow_back; its font is still loading or failed to load) THE search SHALL draw nothing in that glyph's place, never the glyph's name as text, SHALL keep the glyph's box so that the bar's layout does not change, SHALL keep the clear and back buttons operable and named by clearLabel and backLabel, and SHALL draw the glyph once the icon set can.
SRC-31 THE search SHALL take its layout direction from where it is used — the direction of the nearest ancestor that sets one, and the platform's own where none does — and SHALL have no direction setting of its own; WHEN that direction changes while the search is shown THE search SHALL draw itself for the new direction at once, without a motion of its own, keeping its value, whether it is expanded, and its focus.
SRC-32 WHERE the layout direction is right-to-left THE search SHALL draw a suggestion's leading icon and the arrow_back of its back button (SRC-11) mirrored left to right exactly when the system's icon set marks that glyph's name as mirrored or the product forces mirroring for that use, and unmirrored when the product forbids it: the icon helper mirrors the glyph inside its own box, about the box's vertical centre line, changing neither its place, size, color and fill nor the order SRC-1 and SRC-16 gives. THE search SHALL NOT mirror a glyph itself, and SHALL NOT mirror content the product gives as an image or a view of its own rather than by a glyph's name. The search glyph and the clear button's close are not marked and are never mirrored (SRC-2, SRC-10); the icon-only Buttons of the leading and trailing slots mirror their own glyphs (BTN-19).
SRC-33 THE search SHALL lay out its placeholder and a suggestion's headline and supporting text as text of its own direction, isolated from the text around it: each takes the base direction of its first strong character, or the layout direction where it has none, so that a left-to-right word, a number with its sign or unit, a telephone number and an address keep their own order in a right-to-left layout and reorder nothing beside them; THE search SHALL still place each and align its lines by the layout direction, not by the text's own.
SRC-34 THE search SHALL lay out the bar's action buttons — the clear button WHILE it is shown (SRC-10) and the icon-only Buttons of the trailing slot — comp.search.container.button-gap from one another, measured between their visible bounds, and SHALL move two of them further apart only as far as each needs in order to keep, centred on itself, a length of sys.target.touch along the row that its neighbour's does not reach into, because buttons that stand this close cannot extend a hit area over each other (as BGR-3): where the token is 0, as in the default system, a button at least sys.target.touch wide touches its neighbour, and a narrower one stands half of what it lacks away from it. The first action button SHALL still stand comp.search.container.gap after the input and the last comp.search.container.padding-inline-with-button from the bar's end edge (SRC-1). THE search SHALL NOT widen, resize or restyle a button to do so (SRC-25), and SHALL space the buttons the same whatever the input type, so that the bar does not change with the pointer.
SRC-35 WHILE bar is button THE search SHALL draw a trigger in place of the bar of SRC-1: one button as wide as its layout gives it and at least comp.search.trigger.container.height high, filled, raised and rounded as the bar is (comp.search.standard.container.color, comp.search.standard.container.elevation, comp.search.container.shape), holding in one row, vertically centered and comp.search.trigger.container.gap apart, the glyph search drawn as SRC-2 says at comp.search.trigger.leading-icon.size, comp.search.trigger.container.padding-inline from the start edge; then the placeholder — or the label WHILE placeholder is empty — on one line in comp.search.trigger.label.typescale and comp.search.standard.placeholder.color, taking the remaining width and cut at its own end where it does not fit (SRC-33); then the shortcut hint WHILE shortcut is not empty (SRC-37); the last of them ending comp.search.trigger.container.padding-inline from the end edge. WHILE bar is icon THE search SHALL draw in the bar's place one icon-only Tanrei Button of the text variant and the medium size showing the glyph search of the system's icon set, rendered from the Button's own tokens, and no hint. In either form THE search SHALL draw no input, no clear button and neither slot in the trigger, and SHALL NOT show the value while collapsed. Right-to-left layouts SHALL mirror the row.
SRC-36 WHILE bar is button or icon THE search SHALL treat its trigger as a button: WHEN it is activated by pointer, touch, Enter or Space THE search SHALL emit toggle once with expanded true and become expanded as SRC-5 says, presenting its view as a modal one — dialog WHILE presentation is dialog or docked, and full-screen WHILE it is full-screen — and in debug builds SHALL report presentation docked with a trigger, because a docked view has no input of its own. WHILE the button trigger is hovered, keyboard-focused or pressed THE search SHALL render its container, outline, outline width, glyph, text and opacity from the bar's component tokens of the highest-precedence state, with precedence pressed over focused over hovered, showing keyboard focus by the focused outline as the bar does (SRC-18); focus gained by pointer or touch SHALL NOT select the focused state, as for a Button; a press SHALL be answered as SRC-19 and SRC-20 say for the bar, and its hit area extended on both axes as SRC-22 says. THE search SHALL expose the trigger as a button named by label that opens a dialog, with whether its view is open (aria-haspopup with the value dialog and aria-expanded on the web), and with the search glyph hidden; WHILE disabled is true the trigger SHALL NOT be focusable or pressable, SHALL expose the disabled state and SHALL render from the disabled tokens (SRC-26).
SRC-37 WHILE shortcut is not empty THE search SHALL draw it with the keyboard shortcut component, hosted as KBS-13 says: in its plain form, at size small, with convention auto, disabled while the search is disabled, its legends and separators in comp.search.shortcut.typescale and comp.search.shortcut.color; it SHALL draw no cap, fill or edge (KBS-7), because the bar's fill may be the cap's own. It SHALL draw the hint at the end of a button trigger (SRC-35) and, WHILE bar is field, after the bar's input and comp.search.container.gap from it, only while the value is empty and the input does not have focus; it SHALL NOT draw it WHILE bar is icon, nor in a view's header. THE search SHALL expose the shortcut as the keyboard shortcut of its trigger, or of its input WHILE bar is field, in the platform's form (KBS-12: aria-keyshortcuts on the web), SHALL hide the drawn keys from assistive technology, and SHALL give the hint no press of its own: a press on it is a press on the trigger or the bar.
SRC-38 WHILE bindShortcut is true, shortcut holds exactly one chord and disabled is false, WHEN the person presses that chord anywhere in the window (read as KBS-1 reads it: mod is Command on Apple platforms and Control elsewhere) THE search SHALL, WHILE collapsed, open as an activation of its trigger does (SRC-36) or, WHILE bar is field, focus its input and expand (SRC-5), and WHILE expanded SHALL collapse with the reason shortcut (SRC-6); and it SHALL keep that press from doing anything else. THE search SHALL NOT act on a press that something else has already taken (a cancelled key event on the web), on a key repeating while held, during an input-method composition, or — for a chord without mod, ctrl or alt — while focus is in an element that takes text, its own input included, so that such a key types there. THE search SHALL listen only while it is part of what is shown (connected to the document, in the view tree) and SHALL stop when it is removed, disabled, or bindShortcut becomes false.
SRC-39 WHILE bindShortcut is false THE search SHALL NOT listen for any key outside itself: the hint and the exposed shortcut say what the product has bound, and the product opens the search by setting expanded. IF bindShortcut is true while shortcut is empty or holds more than one chord, or while another shown search binds the same chord, THE search SHALL bind nothing for itself — the search shown first keeps a chord two of them name — and in debug builds SHALL report it.
SRC-40 WHEN expanded becomes true WHILE presentation is dialog THE search SHALL present the view as a modal overlay on its modal layer (MDL-1, MDL-2, MDL-4): the layer's scrim in comp.search.view.scrim.color and comp.search.view.scrim.blur over the whole window, and above it a container centered between the window's side edges, its top comp.search.view.dialog.offset below the top of the safe area, as wide as the window allows up to comp.search.view.dialog.max-width while keeping comp.search.view.viewport-margin from each side edge, and as tall as its content up to the room left above comp.search.view.viewport-margin from the bottom of the safe area or from the on-screen keyboard; WHERE the window is too short to keep the offset and one row of content, it SHALL give up the offset down to comp.search.view.viewport-margin. It SHALL fill the container with comp.search.view.container.color, raise it by comp.search.view.container.elevation, round it by comp.search.view.container.shape and clip its content to that shape. At the container's top it SHALL draw a header at least comp.search.header.height high: the back button the full-screen view's header draws, drawn, mirrored, named by backLabel, reported and answered as SRC-11 says, comp.search.header.padding-inline from the start edge, where the full-screen header has it and in the search glyph's place, the input with the same value, and the clear button WHILE it is shown (SRC-10, at the medium size), comp.search.container.gap apart and vertically centered, the last ending comp.search.header.padding-inline from the end edge when it is the clear button and comp.search.container.padding-inline when it is the input; it SHALL draw no search glyph in the header. The back button SHALL be a stop of the view's focus order, so that a person can leave the view without Escape, a pointer or the scrim. WHILE the view has content under the header THE search SHALL draw a line of comp.search.divider.thickness in comp.search.divider.color across the container under it, then the content in the order SRC-46 gives, inset by comp.search.view.padding-block and comp.search.view.padding-inline and scrolling under the header when it is taller than the room. It SHALL move focus, keep it inside, make everything outside inert and hidden from assistive technology, and return focus when the view closes, all as SRC-9 says for the full-screen view; and it SHALL keep the container's top where it is while its content changes, so that the input does not move under the person's typing.
SRC-41 WHEN the dialog view opens THE search SHALL fade its scrim and its container in together (MDL-7, with the search's own motion, which its docked view shares) over comp.search.motion.open-duration with comp.search.motion.open-easing, and WHEN it closes SHALL fade both out over comp.search.motion.close-duration with comp.search.motion.close-easing, as SRC-23 says of the other views; WHEN the container's height changes with its content THE search SHALL draw the new height at once, without a motion of its own.
SRC-42 THE search SHALL lay out a result as a suggestion's row is laid out (SRC-16), from the same tokens: the leading icon column, then the headline in comp.search.suggestion.headline.typescale with the excerpt under it in comp.search.suggestion.supporting-text.typescale, both wrapping and growing the row rather than being cut, the row at least comp.search.suggestion.container.height.regular tall and at least the minimum target, and the whole row the result's hit area. The leading icon column SHALL be kept as SRC-52 says, the suggestions and the results of the view decided together, so that they align. WHILE a result is hovered, focused, current (SRC-49) or pressed THE search SHALL render its row from the suggestion tokens of that state (comp.search.standard.suggestion.container.color and the leading icon, headline and supporting-text colors, the excerpt taking the supporting-text color) with the precedence, the focus ring inside the row and the press answer that SRC-17, SRC-19 and SRC-20 give a suggestion, focused and current standing where active stands there.
SRC-43 THE search SHALL read an excerpt as runs of text in order, the second, fourth and every further even run being a match, SHALL draw the runs as one continuous text that wraps as one, and SHALL draw each match in comp.search.result.mark.color with its weight raised by comp.search.result.mark.emphasis, over a fill of comp.search.result.mark.container.color that covers the match's own line boxes, with square corners and no padding, so that the fill moves no text. A match SHALL be told from the excerpt around it by all three — color, weight and fill — because a match must not depend on color alone, and the reader's font, which the product does not choose, may have no weight between regular and bold, so that the raised weight draws as the regular one (an Arabic font often has none); the fill shows a match in every script, as the platform's own marked text is filled. A result is a destination, so what is marked in it is what matched; a query suggestion marks what it adds (SRC-56). THE search SHALL NOT look for the query in a result's text, mark a result's headline, or change, trim or shorten an excerpt: what matched and how long the passage is are the product's. It SHALL expose the excerpt to assistive technology as one text, the result's description, read without a pause or an announcement at a mark, and SHALL lay the whole excerpt out as text of its own direction (SRC-33).
SRC-44 THE search SHALL draw a result group as its heading followed by its results in order, comp.search.group.gap below whatever stands above it in the view and above whatever follows it. WHILE the group's href is empty its heading SHALL be the headline in comp.search.group-title.typescale and comp.search.group-title.color, wrapping, inset by comp.search.suggestion.container.padding-inline.regular at the sides and padded by comp.search.suggestion.container.padding-block.regular above and below, taking no input and no state. WHILE href is not empty the heading SHALL be a result's row (SRC-42, SRC-45) made of the group's headline, excerpt and leading icon, and the group's results SHALL be inset at the start by comp.search.group.indent, their hit areas and highlights with them, so that they read as parts of it. A group SHALL hold results only, and SHALL NOT hold a group. Right-to-left layouts SHALL mirror the inset.
SRC-45 THE search SHALL make each result, and each group heading, whose href is not empty a link and not an option or a button: the platform's own link to href (the web's anchor element; elsewhere an element with the platform's link semantics whose address the platform's opener opens), so that whatever the platform gives a link — on the web following it by Enter or a press, opening it in a new tab by a modifier key or the middle button, its context menu, dragging and copying its address, the address shown before it is followed — is the platform's and not the search's to imitate; it SHALL activate a link by pointer, touch or Enter and not by Space, SHALL open it in a new context WHILE target is new (on the web one that is given no handle to the page that opened it) and expose targetLabel as its description after the excerpt, and SHALL draw no mark of its own for a new context. WHEN a result is activated in place (by Enter, touch or a primary press, without a modifier key, target being same) THE search SHALL emit select once with the result's value and then let the platform open href, unless the product cancelled that select, in which case it SHALL open nothing because the product's router has taken it; and SHALL then collapse with the reason select (SRC-6), so that toggle follows select. WHEN a result is opened any other way (a modifier key, the middle button, the context menu, target new) THE search SHALL emit nothing and stay expanded, so that a person can open several results from one search. WHILE a result's href is empty, or names a script rather than a place, it SHALL be a button, activated by pointer, touch, Enter or Space, for which select is all that happens.
SRC-46 WHILE expanded THE search SHALL lay out the content of its view from top to bottom in this order: the suggestions, the status row (SRC-47), the results and result groups in the order the product gives them, and the default slot's content; a part that is absent takes no room.
SRC-47 WHILE statusText is not empty or status is loading THE search SHALL draw a status row: inset by comp.search.suggestion.container.padding-inline.regular at the sides and padded by comp.search.suggestion.container.padding-block.regular above and below, taking no input and no state. WHILE status is idle it SHALL draw statusText, wrapping, in comp.search.status.typescale and comp.search.status.color; WHILE status is error it SHALL draw it in comp.search.status.error.color; WHILE status is loading it SHALL draw, in the text's place and at the row's start, one Tanrei loading indicator of size small named by statusText, which waits its own show delay and enters as the loading indicator does (LDG-11 to LDG-14), and no text, and the row SHALL keep the height of one line of text whether or not the indicator is shown yet. The results the product leaves in the view WHILE status is loading SHALL stay drawn and usable.
SRC-48 THE search SHALL expose the status row as a live region that is present from the moment the view opens: WHILE status is idle, WHEN statusText changes THE search SHALL have assistive technology read the new text politely, after what it is saying (the status role on the web); WHILE status is error it SHALL have it read at once (the alert role); WHILE status is loading it SHALL announce nothing — the loading indicator does not announce itself (LDG-6) — and SHALL mark the results as busy (aria-busy on the web) until status leaves loading. THE search SHALL NOT compose, count or translate the text: the number of results and the words around it are the product's.
SRC-49 WHILE expanded, the input has focus and the view holds a result and no suggestion THE search SHALL make the first result current automatically, focus staying in the input, as SRC-14 makes its first place current and, as there, not WHILE the person types on an on-screen keyboard or an input method is composing: WHEN the view comes to show results — it opens with them, the product gives or replaces them, or focus comes back to the input — and WHEN the person types, deletes or pastes. It SHALL draw the current result as a focused one (SRC-42), and the action key in the input SHALL activate it as Enter on it does (SRC-45), so that one press of Enter goes to what the search found first, as a documentation search does. With the modifier that opens a link elsewhere — Command under the Apple keyboard convention and Control under the others for a new tab, Shift for a new window — the action key in the input SHALL open the current result's destination there, as that press on the link does: nothing emitted and the view kept open (SRC-45); a current result without a destination takes no such press. WHILE the input does not have focus no result SHALL be current. The results SHALL be the last rows of the arrow keys' cycle (SRC-14), in view order, across groups, a linked group heading counting as a result and a title not, and an arrow key that reaches a result SHALL move focus to it: WHEN the person presses Down Arrow in the input while the first result is current THE search SHALL move focus to the second result, and to the first WHILE no result is current and there is no suggestion to go to (none in the view, or the last one active). WHILE a result has focus THE search SHALL move focus to the next result with Down Arrow and to the previous one with Up Arrow; Up Arrow on the first SHALL go back to the input with the last suggestion active, where the view holds suggestions; and at the ends of the cycle, WHILE wrap is true, Down Arrow on the last result SHALL go to the first place of the cycle — focus going back to the input, to the query row or the input's place, or, with no suggestion, to the first result — and, with no suggestion in the view, Up Arrow on the first result, whether it has focus or is current in the input, SHALL move focus to the last result; WHILE wrap is false they SHALL do nothing there. WHEN a result takes focus or becomes current while part of it is scrolled out of view THE search SHALL scroll it into view, and SHALL show the focus ring inside its row (SRC-42). WHILE a result has focus, WHEN the person types a character, deletes or pastes THE search SHALL move focus to the input so that the key edits the value there, and Escape SHALL close the view as from the input (SRC-6). Tab and Shift+Tab SHALL move through the results as through any links WHILE the view is modal, and SHALL leave the search and close the view WHILE it is docked (SRC-6). A pointer over a result SHALL NOT move focus, and the arrows SHALL NOT reach the status row or the default slot's content.
SRC-50 THE search SHALL expose its results as links in a list, outside the suggestions' listbox: one list named by label holding the results in order, each result a link named by its headline and described by its excerpt, with its position in the list where the platform gives one; a result group as a group named by its headline holding its own list of its results, and a linked heading as a link before that list; a result without href as a button in the same place. A result SHALL never carry the option role: an option cannot be a link, and a result must be one. The result current while focus stays in the input (SRC-49) SHALL be announced as the query row is (SRC-24) — on the web the input names the result's link as its active descendant once it has stayed current for 500 milliseconds with nothing typed —, the input staying a search box; what the search found is also said by the status row (SRC-48), and the result takes real focus as soon as the person moves to it. On the platforms without a link element THE search SHALL expose a result as a button with the link trait or role where the platform has one, named and described the same way. Leading icons SHALL be hidden, and the status row is exposed as SRC-48 says.
SRC-51 THE search SHALL NOT run a query, fetch, wait, debounce, cache, sort or filter anything itself: it emits input once per change (SRC-4) and draws the suggestions, the results, the status and the statusText the product gives it, replacing them when the product does, at once and without a motion of its own. WHEN the result that has focus is removed or replaced, or the product replaces its content whole so that the element that held the focus goes with it, THE search SHALL move focus to the input rather than let it fall out of the view; WHEN the product sets results or status while the view is collapsed THE search SHALL keep them for the next time it opens and SHALL NOT expand.
SRC-52 THE search SHALL decide the leading icon column for its view as a whole — its suggestions, its query row, its results and the linked headings of its result groups (SRC-16, SRC-42, SRC-44, SRC-57) — as iconSpace says. WHILE iconSpace is auto every row SHALL keep the column, empty where it has no icon, WHERE any suggestion or result of the view has a leading icon — the query row, drawn with the search glyph, counting as one that has —, so that the headlines of the view start on one line, and no row SHALL keep it WHERE none has one; WHILE iconSpace is always every row SHALL keep it, whether or not any has an icon; WHILE iconSpace is never a row SHALL have the column only where it has a leading icon itself. The column kept is comp.search.suggestion.leading-icon.size.regular wide with comp.search.suggestion.container.gap.regular after it, draws nothing and is nothing to assistive technology. WHEN a suggestion or a result is added or removed, or its leadingIcon changes, or the query row is drawn or taken away, THE search SHALL decide again; WHEN iconSpace names a value the search does not define THE search SHALL treat it as auto and in debug builds report the unknown value.
SRC-53 THE search SHALL draw every row of its view — a suggestion, a result, a result group's linked heading — at its density. WHILE density is regular a row SHALL take the regular value of every token of the density axis this spec names (comp.search.suggestion.container.height.regular, comp.search.suggestion.container.padding-block.regular, comp.search.suggestion.container.padding-inline.regular, comp.search.suggestion.container.gap.regular, comp.search.suggestion.leading-icon.size.regular); WHILE density is compact it SHALL take the compact value of each in its place (comp.search.suggestion.container.height.compact, comp.search.suggestion.container.padding-block.compact, comp.search.suggestion.container.padding-inline.compact, comp.search.suggestion.container.gap.compact, comp.search.suggestion.leading-icon.size.compact), so that a compact row is lower, set in less from its edges and draws a smaller glyph, the room kept for an empty leading icon column (SRC-52) shrinking with it. The text styles, the group titles, the status row, the view's surface, its header and the bar SHALL be the same in both. WHEN density names a value the active design system does not have THE search SHALL draw the default density's rows and in debug builds report the unknown value; a density a design system added SHALL be drawn from that density's tokens, as the core values are. WHEN density changes while the view is shown THE search SHALL draw the new rows at once, without a motion, keeping the active row.
SRC-54 WHERE the platform has ARIA attributes (the web), WHEN the product sets an aria- attribute on the host, by the attribute or by the ARIA property that reflects it, THE search SHALL move it to the data-aria- attribute of the same name, so that the host is no second node with its name, description or state, and SHALL expose it on the element that carries its role — an id reference by the elements it names in the host's tree or a tree around it, an error message as part of the description while the search is invalid — except those the search owns (aria-haspopup, aria-expanded, aria-controls, aria-keyshortcuts, aria-disabled), which it SHALL move and not expose. WHEN the product removes the aria- attribute or its data-aria- twin, or sets the ARIA property that reflects it (ariaLabel, ariaDescribedByElements…) to null, THE search SHALL take it off that element. WHEN the product sets an aria- attribute the search owns THE search SHALL report it in debug builds.
SRC-55 WHILE inlineCompletion is true and the query row is drawn (SRC-57), WHEN the person inserts text at the end of the value — by typing, or as an input method commits its composition — or the product gives or replaces the suggestions after such an insertion, THE search SHALL complete the value in the input from the first suggestion, in the product's order, whose headline begins with the value and is longer than it, compared as the combobox compares a label with what was typed (CMB-25): it SHALL write the rest of that headline after the value, selected, with the caret before it, without changing value or emitting input, and the query row SHALL show the completed text and stay active. THE search SHALL NOT complete after the person deleted (Backspace, Delete, a cut) or pasted, until they insert text again; WHILE an input method is composing; WHILE the person types on an on-screen keyboard (SRC-14); WHILE the caret is not at the end of the value or the person has selected text; or WHERE no suggestion's headline begins with the value. WHEN the person moves the caret or the selection — an arrow key, Home, End, a press in the input — THE search SHALL accept the completion: the completed text SHALL become the value, input SHALL be emitted once, and the caret SHALL move as the key or the press moves it. WHEN the person presses Backspace or Delete while a completion is shown THE search SHALL take the completion away and nothing else: the value stays as typed, no input is emitted, and nothing is completed again until the person inserts text. Typing a character SHALL replace the completion and go on from the value as typed, which may be completed again; WHEN an input method begins to compose while a completion is shown, its first inserted text SHALL replace the completion as a typed character does, and WHEN the composition is cancelled before it inserted anything THE search SHALL take the completion away as Backspace does: the value stays as typed and no input is emitted. The action key SHALL accept the completion and then submit (SRC-13). WHEN an arrow key makes a suggestion active the input SHALL show that suggestion (SRC-14), and WHEN the query row becomes current again THE search SHALL show the completion again as it was. WHEN the view closes or the input loses focus THE search SHALL take an unaccepted completion away. WHILE inlineCompletion is false or queryRow is none THE search SHALL complete nothing.
SRC-56 WHILE the value is not empty THE search SHALL draw, in the headline of each suggestion that begins with the value — compared as SRC-55 compares —, the rest of the headline, its completion, with its weight raised by comp.search.suggestion.completion.emphasis over the weight of comp.search.suggestion.headline.typescale, in the headline's own color and with no fill, as a web search draws what each suggestion would add to what was typed: the person knows what they typed, and tells the suggestions apart by what each adds. A headline that does not begin with the value SHALL be drawn without emphasis; the query row's headline is the value itself, and only an inline completion shown after it is emphasised (SRC-57, SRC-55). The completion SHALL wrap with the headline as one text, move no letter of it, and be read as part of the headline, without a pause or an announcement. THE search SHALL NOT emphasise anything in a suggestion's supporting text, and the excerpt of a result marks what matched instead (SRC-43).
SRC-57 WHILE queryRow is first, the view shows suggestions and the value is not empty THE search SHALL draw a query row above the first suggestion: a suggestion's row (SRC-16, SRC-17, SRC-19, SRC-20, SRC-53), drawn from the suggestion tokens, holding in its leading icon column the glyph search of the system's icon set, drawn as a suggestion's leading icon and never mirrored (SRC-2), the value as typed as its headline — followed by the inline completion WHILE one is shown, emphasised as SRC-56 says —, and queryRowText as its supporting text WHILE queryRowText is not empty. It is the search's own row and holds no word of the search's own: what it says beside the query is the product's, and the glyph and the query alone are a whole row. It SHALL be the row the search makes active automatically (SRC-14), so that the action key always searches for the value as typed (SRC-13), as the first row of a browser's address bar does; WHEN the person presses it by pointer or touch, or presses the action key while it is active, THE search SHALL submit as SRC-13 says, focus staying in the input, and SHALL NOT emit select. It is never a query of its own to fill the input with: WHEN it becomes current again the input shows the value as typed (SRC-14). THE search SHALL expose it as the first option of the suggestions' listbox, named by its headline and described by queryRowText, counted in the options' positions. WHILE queryRow is none THE search SHALL draw no query row; WHEN queryRow names a value the search does not define THE search SHALL draw the query row as for first and in debug builds report the value.

各平台名称对照

对等并不意味着 API 完全相同。同一份契约,由各平台以自己的惯用方式表达。

规格 Web SwiftUI Jetpack Compose Flutter React Native
组件 tanrei-search TanreiSearch TanreiSearch TanreiSearch Search
presentation · 属性 presentation presentation presentation presentation presentation
bar · 属性 bar bar bar bar bar
value · 属性 value text value controller value
label · 属性 label label label semanticLabel accessibilityLabel
placeholder · 属性 placeholder prompt placeholder hintText placeholder
expanded · 属性 expanded isExpanded expanded controller expanded
disabled · 属性 disabled disabled enabled enabled disabled
clearLabel · 属性 clearLabel clearLabel clearLabel clearLabel clearLabel
backLabel · 属性 backLabel backLabel backLabel backLabel backLabel
shortcut · 属性 shortcut shortcut shortcut shortcut shortcut
bindShortcut · 属性 bindShortcut bindsShortcut bindShortcut bindShortcut bindShortcut
status · 属性 status status status status status
statusText · 属性 statusText statusText statusText statusText statusText
queryRow · 属性 queryRow queryRow queryRow queryRow queryRow
queryRowText · 属性 queryRowText queryRowText queryRowText queryRowText queryRowText
inlineCompletion · 属性 inlineCompletion inlineCompletion inlineCompletion inlineCompletion inlineCompletion
wrap · 属性 wrap wrap wrap wrap wrap
iconSpace · 属性 iconSpace iconSpace iconSpace iconSpace iconSpace
density · 属性 density density density density density
input · 事件 input text onValueChange onChanged onChangeText
submit · 事件 submit onSubmit onSearch onSubmitted onSubmitEditing
select · 事件 select onSelect onSelect onSelected onSelect
toggle · 事件 toggle isExpanded onExpandedChange onExpandedChanged onExpandedChange
备注 A form-associated custom element, as the text field is: it takes name and submits its value. It renders an <input type="search" enterkeyhint="search"> in its shadow root, with the web's own cancel button hidden. Attributes are kebab-case (clear-label, back-label, query-row, query-row-text, inline-completion); wrap defaults to true, so its attribute is the inverse, no-wrap, as a boolean attribute cannot default to true. The suggestions are <tanrei-search-suggestion> children; the leading and trailing slots are named slots, and other children are the view's default content. The docked view is a manual popover in the top layer, placed with CSS anchor positioning and a script fallback, with the search's own light dismiss so that toggle carries a reason; a press outside also reaches the element under it. The full-screen view is a <dialog> opened with showModal(). The element sets its own expanded before firing toggle, which is a CustomEvent whose detail holds expanded and reason; submit is cancelable. The inline attribute, for tests, draws the open view in place. The leading glyph is the icon helper's search; the clear and back buttons show close and arrow_back (SRC-2, SRC-10, SRC-11). Not built yet: bar="button" and bar="icon" render a <button> (the icon form a <tanrei-button icon-only>) with aria-haspopup="dialog", aria-expanded and aria-keyshortcuts; the dialog view is a <dialog> opened with showModal(), its scrim the ::backdrop, a press on which closes it with the reason outside; shortcut is an attribute of chords separated by spaces, as the keyboard shortcut's keys; bind-shortcut adds one keydown listener on the window while the element is connected. The status row is a role="status" element that exists from the first render (role="alert" while status="error"). Results are <tanrei-search-result> and <tanrei-search-result-group> children; focus moves to their anchors with focus(), and select on a result is cancelable. The query row is an option of the search's own in its shadow root, first in the listbox (id="query-row"). A suggestion an arrow key reaches is written into the input element without setting value or firing input; the element is written back from value when the person returns. The inline completion is a selection range after the typed text; the input a Backspace fires to take it away, which changes no value, is stopped in the shadow root. An automatic row is named by aria-activedescendant 500 ms after it became current, from a timer each edit restarts and clears. A result's link is its own light-DOM child (the <a>, or the <button> without href), slotted over the row the result draws in its shadow root and drawn as nothing itself, so that the input reaches it as its active descendant by element reflection (ariaActiveDescendantElement): an id cannot cross a shadow root, and reflection reaches out into the document, never into another shadow root. An on-screen keyboard (SRC-14) is told by the pointerType of the press that focused the input — touch or pen — and a hardware keyboard by its arrow and caret keys; (pointer: coarse) describes only the primary pointer, and the VirtualKeyboard API is Chromium's alone. TanreiSearch(_ label:, text: Binding<String>, isExpanded: Binding<Bool>, presentation:, prompt:, clearLabel:, backLabel:, onSubmit:, onSelect:) { suggestions } leading: { … } trailing: { … } content: { … }. Every edit writes the text binding, which is the input event; opening and closing write isExpanded, which is toggle (the reason is passed to an optional onToggle). SwiftUI's .searchable is not used: its field and suggestions cannot take the tokens. The docked view is drawn in an overlay above the window's content, anchored to the bar, not with .popover, which is modal at compact widths and would take focus from the field (SRC-8). The full-screen view is presented with .fullScreenCover, with the system transition off, as the dialog is. The input has the search-field trait. disabled follows .disabled(_:). Snapshot harness: renders the bar and the open view in place, as the menu and the dialog do. Without an installed icon font it strokes the search and back glyphs as shapes of its own (TanreiSearchMagnifierShape, TanreiSearchBackArrowShape) instead of drawing nothing (SRC-2, SRC-30). Not built on this platform yet: queryRow, queryRowText, inlineCompletion and wrap (it draws no query row, completes nothing and stops the arrow keys at the ends), bar, the dialog presentation, shortcut (where bindsShortcut would be .keyboardShortcut on the trigger), status, statusText, iconSpace (SRC-52: it keeps the leading icon column in every row while any suggestion has an icon) and the result kinds. Compose idiom, as Material's SearchBar with its input field: TanreiSearch(value, onValueChange, expanded, onExpandedChange, label, modifier, presentation, placeholder, enabled, clearLabel, backLabel, onSearch, onSelect, leading, trailing) { suggestions and content }. State hoisting: the caller keeps value and expanded and moves them from onValueChange and onExpandedChange, which receives the new value and the reason. enabled is the inverse flag. Built on BasicTextField with the search IME action. The docked view is a Popup that does not take focus; the full-screen view is a Dialog window with usePlatformDefaultWidth = false and the window's own dim off, as the dialog's. Compose has no combobox or listbox role: the suggestions are buttons in a column with collection semantics. Snapshot harness: renders the bar and the open view in place. Without an installed icon font it strokes the clear button's close as a vector of its own (TanreiDrawnGlyph), and draws search and arrow_back as their names in the platform font, clipped to the box (TanreiNamedGlyph), instead of drawing nothing (SRC-2, SRC-30). Not built on this platform yet: queryRow, queryRowText, inlineCompletion and wrap (it draws no query row, completes nothing and stops the arrow keys at the ends), bar, the dialog presentation, shortcut, bindShortcut (a key handler on the window's root, where a hardware keyboard exists), status, statusText, iconSpace (SRC-52: it keeps the leading icon column in every row while any suggestion has an icon) and the result kinds. Flutter idiom, as Material's SearchAnchor and SearchController but without Material: TanreiSearch(controller: TanreiSearchController, semanticLabel:, presentation:, hintText:, enabled:, clearLabel:, backLabel:, onChanged:, onSubmitted:, onSelected:, onExpandedChanged:, leading:, trailing: [...], suggestions: [...], child:). TanreiSearchController is a TextEditingController that also holds isExpanded with expand() and collapse(); the search updates it itself and calls onExpandedChanged with the value and the reason. The input is EditableText with TextInputAction.search and SemanticsInputType.search (Flutter 3.32, the oldest version supported, asserts on SemanticsRole.searchBox). The docked view is drawn through an OverlayPortal; the full-screen view is a modal route that scopes semantics, as the dialog's. Snapshot harness: a golden of the bar and the open view. Lagging behind SRC-30: it writes the built-in glyphs as Material Symbols code points (tanreiSearchGlyph, tanreiCloseGlyph, tanreiArrowBackGlyph), and without the icon font it draws whatever the fallback face has at those code points instead of nothing. Not built on this platform yet: queryRow, queryRowText, inlineCompletion and wrap (it draws no query row, completes nothing and stops the arrow keys at the ends), bar, the dialog presentation, shortcut, bindShortcut (a HardwareKeyboard handler), status, statusText, iconSpace (SRC-52: it keeps the leading icon column in every row while any suggestion has an icon) and the result kinds. Controlled, in TextInput's idiom: <Search value onChangeText expanded onExpandedChange accessibilityLabel placeholder presentation clearLabel backLabel onSubmitEditing onSelect suggestions={[…]} leading trailing insets>{content}</Search>; the caller moves value and expanded from onChangeText and onExpandedChange, which receives the new value and the reason. The input is a TextInput with returnKeyType="search" and accessibilityRole="search". The docked view is on the overlay layer that TanreiProvider renders, not a Modal (which would take focus from the field); the full-screen view is a transparent Modal with statusBarTranslucent and navigationBarTranslucent, its insets from the insets prop or TanreiProvider's. Android's back button (BackHandler) closes the view. Snapshot harness: renders the bar and the open view in place. Lagging behind SRC-30: without the icon font the built-in glyphs print their ligature names. Not built on this platform yet: queryRow, queryRowText, inlineCompletion and wrap (it draws no query row, completes nothing and stops the arrow keys at the ends), bar, the dialog presentation, shortcut, status, statusText, iconSpace (SRC-52: it keeps the leading icon column in every row while any suggestion has an icon) and the result kinds; bindShortcut does nothing where there is no hardware keyboard event to listen to, and the README says so.

令牌

令牌 引用 解析值(浅色)
--tanrei-comp-search-container-button-gap sys.space.space0 0px
--tanrei-comp-search-container-gap — 16px
--tanrei-comp-search-container-height — 56px
--tanrei-comp-search-container-padding-inline sys.space.space200 16px
--tanrei-comp-search-container-padding-inline-with-button sys.space.space100 8px
--tanrei-comp-search-container-shape sys.shape.corner.full 9999px
--tanrei-comp-search-disabled-opacity — 1
--tanrei-comp-search-disabled-outline-width — 1px
--tanrei-comp-search-divider-color sys.color.outline-variant #000000 · 8%
--tanrei-comp-search-divider-thickness sys.border.hairline 1px
--tanrei-comp-search-focused-opacity — 1
--tanrei-comp-search-focused-outline-width — 2px
--tanrei-comp-search-group-title-color sys.color.on-surface-variant #4b4b4b
--tanrei-comp-search-group-gap sys.space.space100 8px
--tanrei-comp-search-group-indent sys.space.space300 24px
--tanrei-comp-search-header-height — 72px
--tanrei-comp-search-header-padding-inline sys.space.space100 8px
--tanrei-comp-search-hovered-opacity — 1
--tanrei-comp-search-hovered-outline-width — 1px
--tanrei-comp-search-leading-icon-size sys.icon.medium 24px
--tanrei-comp-search-motion-close-duration sys.motion.role.appear.anchored.exit 250ms
--tanrei-comp-search-motion-close-easing sys.motion.easing.exit cubic-bezier(0.3, 0, 1, 1)
--tanrei-comp-search-motion-feedback-duration sys.motion.role.feedback 450ms
--tanrei-comp-search-motion-open-duration sys.motion.role.appear.anchored.enter 300ms
--tanrei-comp-search-motion-open-easing sys.motion.easing.enter cubic-bezier(0.2, 0, 0, 1)
--tanrei-comp-search-motion-state-duration sys.motion.role.state.default 250ms
--tanrei-comp-search-motion-state-easing sys.motion.easing.state cubic-bezier(0.2, 0, 0, 1)
--tanrei-comp-search-outline-width sys.border.hairline 1px
--tanrei-comp-search-pressed-opacity — 1
--tanrei-comp-search-pressed-outline-width — 1px
--tanrei-comp-search-result-mark-color sys.color.on-surface #1b1b1b
--tanrei-comp-search-result-mark-container-color sys.color.secondary-container #eeeeee
--tanrei-comp-search-result-mark-emphasis sys.typescale.emphasis.body 100
--tanrei-comp-search-shortcut-color sys.color.on-surface-variant #4b4b4b
--tanrei-comp-search-standard-caret-color sys.color.primary #1b1b1b
--tanrei-comp-search-standard-container-color sys.color.surface-container-highest #eeeeee
--tanrei-comp-search-standard-container-elevation sys.elevation.level0
--tanrei-comp-search-standard-disabled-caret-color — #1b1b1b · 38%
--tanrei-comp-search-standard-disabled-container-color — #eeeeee
--tanrei-comp-search-standard-disabled-container-elevation —
--tanrei-comp-search-standard-disabled-input-color — #1b1b1b · 38%
--tanrei-comp-search-standard-disabled-leading-icon-color — #1b1b1b · 38%
--tanrei-comp-search-standard-disabled-outline-color — #000000 · 0%
--tanrei-comp-search-standard-disabled-placeholder-color — #1b1b1b · 38%
--tanrei-comp-search-standard-disabled-state-layer-color — #1b1b1b · 38%
--tanrei-comp-search-standard-disabled-suggestion-container-color — #000000 · 0%
--tanrei-comp-search-standard-disabled-suggestion-headline-color — #1b1b1b · 38%
--tanrei-comp-search-standard-disabled-suggestion-leading-icon-color — #1b1b1b · 38%
--tanrei-comp-search-standard-disabled-suggestion-state-layer-color — #1b1b1b · 38%
--tanrei-comp-search-standard-disabled-suggestion-supporting-text-color — #1b1b1b · 38%
--tanrei-comp-search-standard-focused-caret-color — #1b1b1b
--tanrei-comp-search-standard-focused-container-color — #eeeeee
--tanrei-comp-search-standard-focused-container-elevation —
--tanrei-comp-search-standard-focused-input-color — #1b1b1b
--tanrei-comp-search-standard-focused-leading-icon-color — #4b4b4b
--tanrei-comp-search-standard-focused-outline-color — #0070ac
--tanrei-comp-search-standard-focused-placeholder-color — #4b4b4b
--tanrei-comp-search-standard-focused-state-layer-color — #1b1b1b
--tanrei-comp-search-standard-focused-suggestion-container-color — #1b1b1b · 10%
--tanrei-comp-search-standard-focused-suggestion-headline-color — #1b1b1b
--tanrei-comp-search-standard-focused-suggestion-leading-icon-color — #4b4b4b
--tanrei-comp-search-standard-focused-suggestion-state-layer-color — #1b1b1b
--tanrei-comp-search-standard-focused-suggestion-supporting-text-color — #4b4b4b
--tanrei-comp-search-standard-hovered-caret-color — #1b1b1b
--tanrei-comp-search-standard-hovered-container-color — #dddddd
--tanrei-comp-search-standard-hovered-container-elevation —
--tanrei-comp-search-standard-hovered-input-color — #1b1b1b
--tanrei-comp-search-standard-hovered-leading-icon-color — #4b4b4b
--tanrei-comp-search-standard-hovered-outline-color — #000000 · 0%
--tanrei-comp-search-standard-hovered-placeholder-color — #4b4b4b
--tanrei-comp-search-standard-hovered-state-layer-color — #1b1b1b
--tanrei-comp-search-standard-hovered-suggestion-container-color — #1b1b1b · 8%
--tanrei-comp-search-standard-hovered-suggestion-headline-color — #1b1b1b
--tanrei-comp-search-standard-hovered-suggestion-leading-icon-color — #4b4b4b
--tanrei-comp-search-standard-hovered-suggestion-state-layer-color — #1b1b1b
--tanrei-comp-search-standard-hovered-suggestion-supporting-text-color — #4b4b4b
--tanrei-comp-search-standard-input-color sys.color.on-surface #1b1b1b
--tanrei-comp-search-standard-leading-icon-color sys.color.on-surface-variant #4b4b4b
--tanrei-comp-search-standard-outline-color — #000000 · 0%
--tanrei-comp-search-standard-placeholder-color sys.color.on-surface-variant #4b4b4b
--tanrei-comp-search-standard-pressed-caret-color — #1b1b1b
--tanrei-comp-search-standard-pressed-container-color — #d9d9d9
--tanrei-comp-search-standard-pressed-container-elevation —
--tanrei-comp-search-standard-pressed-input-color — #1b1b1b
--tanrei-comp-search-standard-pressed-leading-icon-color — #4b4b4b
--tanrei-comp-search-standard-pressed-outline-color — #000000 · 0%
--tanrei-comp-search-standard-pressed-placeholder-color — #4b4b4b
--tanrei-comp-search-standard-pressed-state-layer-color — #1b1b1b
--tanrei-comp-search-standard-pressed-suggestion-container-color — #1b1b1b · 10%
--tanrei-comp-search-standard-pressed-suggestion-headline-color — #1b1b1b
--tanrei-comp-search-standard-pressed-suggestion-leading-icon-color — #4b4b4b
--tanrei-comp-search-standard-pressed-suggestion-state-layer-color — #1b1b1b
--tanrei-comp-search-standard-pressed-suggestion-supporting-text-color — #4b4b4b
--tanrei-comp-search-standard-state-layer-color comp.search.standard.input.color #1b1b1b
--tanrei-comp-search-standard-suggestion-container-color — #000000 · 0%
--tanrei-comp-search-standard-suggestion-headline-color sys.color.on-surface #1b1b1b
--tanrei-comp-search-standard-suggestion-leading-icon-color sys.color.on-surface-variant #4b4b4b
--tanrei-comp-search-standard-suggestion-state-layer-color comp.search.standard.suggestion.headline.color #1b1b1b
--tanrei-comp-search-standard-suggestion-supporting-text-color sys.color.on-surface-variant #4b4b4b
--tanrei-comp-search-status-color sys.color.on-surface-variant #4b4b4b
--tanrei-comp-search-status-error-color sys.color.error #cd262f
--tanrei-comp-search-suggestion-completion-emphasis — 300
--tanrei-comp-search-suggestion-container-gap-compact comp.tree-view.container.gap.compact 8px
--tanrei-comp-search-suggestion-container-gap-regular sys.space.space200 16px
--tanrei-comp-search-suggestion-container-height-compact comp.tree-view.container.height.compact 32px
--tanrei-comp-search-suggestion-container-height-regular — 56px
--tanrei-comp-search-suggestion-container-padding-block-compact — 4px
--tanrei-comp-search-suggestion-container-padding-block-regular — 8px
--tanrei-comp-search-suggestion-container-padding-inline-compact comp.tree-view.container.padding-inline.compact 8px
--tanrei-comp-search-suggestion-container-padding-inline-regular sys.space.space200 16px
--tanrei-comp-search-suggestion-container-shape — 4px
--tanrei-comp-search-suggestion-leading-icon-size-compact sys.icon.small 20px
--tanrei-comp-search-suggestion-leading-icon-size-regular sys.icon.medium 24px
--tanrei-comp-search-trigger-container-gap sys.space.space100 8px
--tanrei-comp-search-trigger-container-height — 40px
--tanrei-comp-search-trigger-container-padding-inline sys.space.space150 12px
--tanrei-comp-search-trigger-leading-icon-size sys.icon.small 20px
--tanrei-comp-search-view-container-color sys.color.surface-bright #ffffff
--tanrei-comp-search-view-container-elevation sys.elevation.level2 0px 0px 0px 1px rgb(0 0 0 / 0.08), 0px 1px 2px 0px rgb(0 0 0 / 0.04)
--tanrei-comp-search-view-container-shape sys.shape.corner.medium 8px
--tanrei-comp-search-view-dialog-max-width — 640px
--tanrei-comp-search-view-dialog-offset sys.space.space800 64px
--tanrei-comp-search-view-offset sys.space.space50 4px
--tanrei-comp-search-view-padding-block sys.space.space50 4px
--tanrei-comp-search-view-padding-inline sys.space.space50 4px
--tanrei-comp-search-view-scrim-blur comp.modal-layer.scrim.blur 0px
--tanrei-comp-search-view-scrim-color comp.modal-layer.scrim.color #000000 · 40%
--tanrei-comp-search-view-viewport-margin sys.space.space100 8px
--tanrei-comp-search-group-title-typescale sys.typescale.label-small 500 12px/1.3333
--tanrei-comp-search-input-typescale sys.typescale.body-large 400 16px/1.625
--tanrei-comp-search-shortcut-typescale sys.typescale.label-small 500 12px/1.3333
--tanrei-comp-search-status-typescale sys.typescale.body-small 400 13px/1.5385
--tanrei-comp-search-suggestion-headline-typescale sys.typescale.body 400 14px/1.5714
--tanrei-comp-search-suggestion-supporting-text-typescale sys.typescale.body-small 400 13px/1.5385
--tanrei-comp-search-trigger-label-typescale sys.typescale.body 400 14px/1.5714

测试样例

作为基准的渲染结果。所有平台都以相同的 ID 为每个样例截取快照,以便相互比较。

生成自 specs/search.spec.json, tokens/comp/search.tokens.json, design/tokens/

指南

何时使用

当搜索是进入产品内容(例如邮件、文件、联系人或设置)的主要途径之一,并且建议能帮助用户更快到达时,使用搜索。把它放在屏幕的顶部,或放在它所搜索的页面的顶部。

它也可以用作站内搜索:页眉中的一个触发器打开对话框,找到的页面和章节以链接的形式列出。

如果只是筛选屏幕上已有的一个短列表,或者在表单中输入一个搜索词,用 type 为 search 的文本字段就够了。从固定列表中选择一个值,是菜单或列表的工作,而不是搜索的工作。

搜索栏还是触发器

bar 页面上显示什么 打开 用途
field(默认) 带输入框的搜索栏 任何呈现方式 搜索是主要进入途径、并且搜索栏有自己位置的产品
button 外形与搜索栏相同的触发器:搜索图标、占位符和快捷键提示 模态视图:对话框或全屏 有空间的页眉,搜索只是其中几样东西之一
icon 纯图标按钮,显示搜索图标 模态视图:对话框或全屏 没有空间的页眉,例如窄窗口

触发器以 label 命名,按钮触发器显示占位符,没有占位符时显示标签。它的视图关闭时,焦点交还给触发器。

停靠、对话框还是全屏

呈现方式 视图在哪里打开 焦点 用途
停靠(默认) 在搜索栏下方,与它等宽,位于内容之上 留在搜索栏的输入框中。其他内容都不会变为惰性(inert),也没有遮罩 大窗口,视图打开时不必遮住整个屏幕
对话框 靠近窗口顶部,居中,不超过最大宽度,位于遮罩之上。内容变化时,它的顶部位置保持不动 移到页眉的输入框,留在视图之内,关闭时交还给触发器或搜索栏 大窗口,由触发器打开:站内搜索
全屏 覆盖整个窗口,有自己的页眉、返回按钮和分隔线 移到页眉的输入框,留在视图之内,关闭时交还给搜索栏或触发器 小窗口,建议和屏幕键盘已经让其他内容无处可放

三种方式下查询词是同一个。在断点处切换 presentation 不会改变它。

清除按钮和返回按钮

两者都是内置的,因为它们的行为属于搜索:清除按钮清空查询词,并让视图和焦点留在原处;返回按钮关闭全屏视图。它们的名称必须使用你的产品语言,所以由你提供:clearLabel(“清除搜索内容”),以及用于对话框和全屏视图的 backLabel(“返回”)。在 iOS 上,返回按钮是离开全屏视图的唯一途径。对话框的页眉里也有返回按钮,这样既没有 Escape 键也没有指针的用户也能离开它。

建议、结果和你的内容

  • 建议是查询词;结果是可以前往的地方。 建议帮助用户补全查询词;方向键让某条建议成为活动建议,而焦点留在输入框中。结果是你的搜索找到的东西:它是一个自己取得焦点的链接。
  • 不要把按原样输入的查询词加进你的建议,那是查询词行的事。如果希望这一行说明 Enter 会做什么,用你产品的语言提供 queryRowText(“搜索全部邮件”“问问助手”)。
  • 根据搜索的用途选择形式。如果 Enter 应当总是搜索用户输入的内容,例如地址栏或邮件搜索,就保留查询词行(默认)。如果是建议排在输入框下方的搜索页面,例如网页搜索页面,就用 queryRow="none"。如果各行都是结果,例如文档搜索,两者都不需要:Enter 打开的是第一个结果。
  • 只有在用户常常把已知的内容输入到底、补全能省去按键的地方,例如网址或名字,才使用 inlineCompletion。搜索页面不会在输入框里补全。
  • 用前置图标区分种类:过去的查询词用历史图标,此外还有文件夹、页面、章节。
  • 只有部分行带图标时,由 iconSpace 决定其他行的标题从哪里开始。auto(默认)在视图中任何建议或结果带图标时,在视图的每一行都为图标保留空间并留空,使标题对齐;always 在每一行都保留,never 只在带图标的行中保留。菜单也有同样的 iconSpace,取值和默认值都相同。
  • density 决定视图中一行占多大空间:regular(默认,高 56)或 compact(高 32,图标 20),后者适用于命令面板,或用鼠标和键盘操作的工具。搜索栏和文字都不变。触摸时行高绝不低于触摸目标。
  • 标题保持简短,细节放进辅助文本或摘录:先是“发票”,再是“文件夹 · 24 条消息”。它们会换行,而不是被截断。
  • 在摘录中标出匹配的部分。这个标记由系统提供,是一种颜色、更粗的字重,以及匹配部分背后的浅色底,所以匹配的部分在各处看起来都一样,在任何文字中都能找到,即使字体在常规和粗体之间没有别的字重。
  • 结果彼此相关时就分组:章节归在所属页面之下,消息归在“消息”之下。组本身是一个可以前往的地方时,组的标题就是链接。
  • 结果只要有地址,就给它 href。这样用户可以在新标签页中打开它、复制它的地址,并看到它通往哪里。只有由你的产品自己打开的结果,才使用不带 href 的 select。
  • 视图中的顺序是固定的:建议、状态行、结果,然后是你自己的内容,例如“加载更多结果”按钮,或通往完整结果页面的链接。
  • 没有内容可显示的停靠视图什么也不画,而搜索保持打开,所以一有内容它就会再次出现。

状态

  • 每个答案只设置一次 statusText:“‘令牌’共 12 条结果”“没有找到‘令排’的结果”。它在变化时会被朗读,所以每次按键都更改它只会成为噪音。
  • 查询进行期间,把 status 设为 loading。加载指示器只在短暂延迟之后出现,所以答案来得快时不会显示它。
  • 把 status 设为 error,并附上说明发生了什么的文本。它会以错误的样式绘制,并立即朗读。
  • 丢弃乱序到达的答案。搜索绘制的是你最后设置的内容。

快捷键

  • 使用用户在你这类产品中已经熟悉的搜索快捷键,并用 mod 来写,这样它在每种键盘上都是对的。
  • 一个屏幕上只在一个搜索上设置 bindShortcut。两个搜索绑定同样的按键时,先显示的那个保有这些按键,另一个会在调试构建中报告。
  • 不带修饰键的快捷键(例如 /),在焦点位于可以输入文本的控件中时会被忽略,这样用户可以输入这个字符。
  • 如果绑定不带修饰键的单个字符键(例如 /),请提供关闭或更改这个快捷键的方法(WCAG 2.1.4 字符键快捷键)。bindShortcut 默认是关闭的。
  • 没有 bindShortcut 时,提示只是显示这些按键:请自己绑定它们,或者让 shortcut 留空。

推荐

  • 占位符要说明可以搜索什么:“搜索邮件”。同时也要设置 label:占位符永远不是名称。
  • 查询词变化时更新建议,并在用户逐条浏览建议时保持它们的顺序稳定。把最匹配的建议放在第一位:按一次下方向键就能到达它;使用 inlineCompletion 时,查询词也是用它补全的。
  • 收到 select 时,做建议所承诺的事:打开一个结果,或者把一个查询词放进搜索栏并执行搜索。
  • 后置插槽中最多放两个图标按钮。
  • 给 target 为 new 的结果一个 targetLabel(“在新标签页中打开”)。

避免

  • 不要在搜索栏仅仅获得焦点时打开视图。搜索本身已经避免了这一点;不要自己再把它加回来。
  • 不要在停靠视图中放需要自己焦点的控件,例如文本字段。在停靠视图上按下时,焦点仍留在输入框中。
  • 不要在某条建议成为活动建议时更改查询词。搜索会把它显示在输入框中,但不更改 value,也不触发 input;只有选择(select)、用户的输入或被接受的补全才会更改查询词。
  • 不要用搜索在表单中选择一个值。
  • 不要只把结果的地址放在 select 里。没有 href 的行是按钮,用户无法在新标签页中打开它。
  • 不要自己只用颜色来标出匹配的部分,也不要把来源不明的标记放进摘录。在 Web 上,摘录的内容是你的:你放进去什么,就原样显示什么。

无障碍

角色
searchbox
标注
label names the search field, the trigger, the suggestions' list, the results' list and the modal views; it is never the placeholder. A suggestion is named by its headline and described by its supporting text; a result by its headline and its excerpt, read as one text with no mention of the marks; a result group by its headline. The status text is announced when it changes, and the loading indicator is named by it. The clear and back buttons are named by clearLabel and backLabel; the slots' icon-only Buttons by their own labels. The search glyph, the leading icons, the drawn shortcut keys, the scrim and the divider are decorative; the shortcut is exposed as the trigger's or the input's keyboard shortcut.
最小目标
即使外观尺寸更小,点击区域也满足最小目标尺寸。 minimum 32px · pointer 44px · spacing 8px · touch 48px

键盘操作

按键 动作
Tab / Shift+Tab Moves focus to the leading icon-only Button, the input, the clear button and the trailing icon-only Buttons in turn, or to the trigger. With the docked view open, leaves the search and closes the view. In a modal view (dialog, full-screen) focus stays inside it and Tab goes through the header's controls, the results and the product's own content.
Enter / Space on the trigger Opens the modal view and moves focus to its input.
The shortcut Where the search binds it (bindShortcut): opens the search from anywhere in the window, and closes it again while it is open.
Typing Edits the value and opens the view while it is closed. With suggestions, the first row is the one Enter takes: the query row — the query as typed, so that Enter searches for it — or, with queryRow none, no row, so that Enter does the same. With results and no suggestions, the first result is current, so that Enter opens it. On an on-screen keyboard (the input focused by a touch or a pen) nothing is, so that its Search or Go key submits the query as typed. With inlineCompletion, the query is completed in the input from the first suggestion that begins with it. While a result has focus, returns focus to the input and edits there.
Down Arrow / Up Arrow Opens the view while it is closed. While it is open, moves through the rows in order: the query row (with queryRow none, the input's own place), the suggestions, then the results, across groups; on a suggestion focus stays in the input, and a result takes focus. Down Arrow goes on from the row Enter takes now, so the first press reaches the second row. A suggestion an arrow key reaches is shown in the input without changing the query, and the query as typed comes back on the query row or the input's place. At the ends they go round — Down on the last row to the first, Up on the first to the last — unless wrap is false, which stops them. The row an arrow key moves to is read out at once; a row the search made current is read once typing pauses for half a second.
Left Arrow, Right Arrow, Home, End Move the caret, and leave the row Enter takes as it is. With an inline completion shown, accept it: the completed query becomes the value.
Backspace / Delete, an inline completion shown Takes the completion away and leaves the query as typed; nothing is completed again until the person types.
Enter In the input: chooses the active suggestion (select) or opens the current result; on the query row, or with no row active, submits the value (submit) — completed first where an inline completion is shown — which closes the view unless it shows results or a status. On an on-screen keyboard nothing is made current by itself, so its Search or Go key submits the value as typed. While an input method is composing, Enter confirms the conversion and does nothing else. With Command (Control off Apple keyboards) or Shift, Enter in the input opens the current result in a new tab or a new window, as the link would with that modifier: nothing is emitted and the view stays. On a result: follows the link, as the platform does, modifier keys included.
Enter / Space on the back button Closes the modal view (dialog, full-screen) and returns focus to the bar's input or the trigger: the way out for a person who has neither Escape nor a pointer.
Escape Closes the view and returns focus to the bar's input or the trigger; while the view is closed, clears the value.

备注

  • Two patterns, by what a row is. Suggestions are queries, in the WAI-ARIA combobox pattern with a listbox popup on the web, in every view: focus stays in the input, and the query as typed is always what Enter takes until the person moves. By default (queryRow first) it is a row of its own, first and active, as the first row of a browser's address bar is (list autocomplete with automatic selection); with queryRow none the input itself is that place and nothing is active, as on a web search page (list autocomplete with manual selection). The arrow keys move through the suggestions and show each in the input without changing the query, and go round at the ends unless wrap is false. inlineCompletion completes the query in the input from a suggestion that begins with it, as an address bar does (list and inline autocomplete). A query suggestion draws what it adds to the query heavier; a result marks what matched. Results are destinations: links in a list, never options, in every view: an option cannot be a link, and a result has to be one (open in a new tab, copy the address, the visited color). Where the view holds results and no suggestion, the first result is current while focus stays in the input, drawn as focused and opened by Enter, as a documentation search does; a result takes real focus once the person moves to it, and the input is a combobox only while the view shows suggestions. A row the search made current by itself — the query row, the first result — is announced once typing pauses for half a second, as React Aria's autocomplete does, so that a screen reader reads the typed character first and then what Enter takes, and not a row after every key; a row an arrow key moves to is announced at once. The dialog and full-screen views are modal dialogs that hold the search field and those links, the pattern of a site search; the docked view with suggestions only is the combobox it was. SwiftUI, Compose, Flutter and React Native have no combobox role: their input is a search field, suggestions are buttons and results are buttons with the link trait or role, each with its position in its list.
  • Overlays: the docked view is an operated overlay that is not modal, and its focus is the input it belongs to until an arrow key takes it to a result; the dialog and full-screen views are modal overlays that take focus, keep it and return it to the bar's input or the trigger.
  • The search never runs a query (SRC-51). The product listens to input, waits as long as its index needs before asking (nothing for an index in memory; a few hundred milliseconds for one over the network), drops an answer that arrives after a newer question, sets status to loading only while it truly waits, and sets statusText once per answer, so that the count is announced once.
  • A shortcut is the product's unless bindShortcut is true. The keyboard shortcut component never listens (KBS-14); the search may, because the command the keys perform is its own: open me.
  • Who closes the view: the search emits toggle; where expanded is a binding or controller (SwiftUI, Flutter) or the element's own property (the web) the search closes it itself, and on Compose and React Native the product sets expanded from toggle, as for the menu.
  • The input edits text as the text field does (TXI-1, TXI-4, TXI-20, TXI-24), and its selection is the text field's pair: comp.input-box.selection.color behind the text, comp.input-box.selection.content.color for it.
  • Heights are minimums: at 200% text size the bar and the header grow, the value stays on one line, and suggestion rows wrap.
  • How a state looks is a value decision of the active design system; components read the state's tokens and never compute the effect themselves.
  • WCAG 2.5.8 (target size): for touch every row of the view is at least the touch target high in both densities (SRC-16). The compact density is lower than the pointer target for a fine pointer, by design: it is the density of a tool used with a mouse and the keyboard, it stays above the 24 by 24 the criterion asks, and its rows reach across the view's whole width. A product that cannot accept that uses regular.

生成自 specs/search.spec.json, tokens/sys/measure.tokens.json

组件负责的部分

  • 输入框是一个以 label 命名的搜索框,绝不以占位符命名;平台有搜索角色时,它带有该角色。
  • 在 Web 上,停靠视图遵循 WAI-ARIA 的 combobox 模式。显示建议时,输入框是一个 combobox,带有 aria-autocomplete="list"(设置 inlineCompletion 时为 both)、aria-expanded、指向列表的 aria-controls,以及指向活动选项的 aria-activedescendant。建议是一个以 label 命名的 listbox:第一个是查询词行,以查询词命名,以 queryRowText 作为描述;后面每条建议以它的标题命名,以它的辅助文本作为描述。活动选项就是被选中的选项。
  • 搜索自己设为活动的行(查询词行)会像 React Aria 的 autocomplete 那样,在输入停顿半秒后才被 aria-activedescendant 指向:屏幕阅读器先读出刚输入的字符,再读出 Enter 会选中的内容,而不会每按一个键就读一行。方向键移到的行会立即被指向。建议中画得更粗的补全部分,作为标题的一部分连着读出。
  • 在停靠视图中,焦点留在输入框中。视图一显示建议,查询词行就成为活动行;查询词或建议每次变化后,又回到这一行。使用 queryRow="none" 时没有活动行,输入框本身就是第一条建议之前的位置。第一次按下方向键会移到活动行的下一行。除非 wrap 为 false,到了两端会循环。活动行有一部分在可见范围之外时,视图会把它滚动进来。
  • 使用屏幕键盘时,查询词行和结果都不会自动成为活动项,也不会补全,因此键盘上的搜索键或前往键会按输入的原样提交查询词,就像手机上的搜索框一样;用户通过点按来选择建议。当触摸或手写笔让输入框获得焦点时,搜索把键盘视为屏幕键盘;按下方向键、移动光标的键,或用鼠标按下输入框之后,又把它视为硬件键盘。设备有没有触摸屏,并不能说明带触摸屏的笔记本电脑或接了键盘的平板电脑正在用哪种键盘。
  • 输入法正在组合文字时,Enter、Escape 和方向键都归输入法使用,没有活动项,也不会补全。确认转换的 Enter 不会选中任何建议;文字上屏之后,查询词行才成为活动行。
  • 全屏视图和对话框视图是以 label 命名的模态对话框。焦点移到页眉的输入框,插入点位于查询词末尾;焦点留在视图之内,视图之外的一切都变为惰性并被隐藏。视图关闭时,焦点交还给搜索栏的输入框或触发器,视图不会再次打开。
  • 触发器是一个以 label 命名的按钮,它表明自己会打开一个对话框,以及它的视图是否打开。它显示键盘焦点的方式与搜索栏相同。
  • 在对话框的遮罩上按下会关闭对话框,并且不会传到它下方的任何内容。对话框的页眉以返回按钮开头,用 Tab 可以到达它。
  • 结果是一个以 label 命名的列表,组以它的标题命名。带 href 的结果是链接,绝不是选项;只有视图显示建议时,输入框才是 combobox。结果以它的标题命名,以它的摘录作为描述;它在新的上下文中打开时,其后还有 targetLabel。
  • 没有建议而有结果时,只要焦点在输入框中,第一个结果就是当前结果。它以获得焦点时的样子绘制,在输入框中按 Enter,会像在这个链接上按 Enter 一样打开它。输入停顿半秒后,这个结果的链接成为输入框的活动后代,屏幕阅读器会读出 Enter 将打开的内容;输入框仍然是搜索框。按下方向键,焦点移到第二个结果,并跨越各个组依次移动。按住 Command(其他键盘上是 Control)或 Shift 在输入框中按 Enter,会像在链接上这样按一样,在新标签页或新窗口中打开当前结果;不发出任何事件,视图保持打开,用户可以接着打开别的结果。
  • 视图中有建议时,在最后一条建议上按下方向键,焦点移到第一个结果;在第一个结果上按上方向键,焦点回到输入框,最后一条建议成为活动建议。焦点在某个结果上时输入、删除或粘贴,焦点会移到输入框,按键随后在那里起作用。在模态视图中,Tab 像经过任何链接一样依次经过各个结果。
  • 状态行是一个实时区域(live region)。statusText 在变化时被朗读;status 为 error 时,它作为警报立即朗读。加载期间,结果被标记为忙碌,加载指示器以 statusText 命名。
  • 快捷键作为触发器或输入框的键盘快捷键暴露。它的提示不接受按下,也不接受焦点。
  • 焦点到达输入框绝不会打开视图,无论是通过 Tab 还是从全屏视图返回。
  • Escape、平台的返回操作和返回按钮会关闭视图。停靠视图还会在按下 Tab、Shift+Tab、在外部按下或焦点离开搜索时关闭。
  • 清除按钮和返回按钮是 Tanrei 的图标按钮,以 clearLabel 和 backLabel 命名。清除之后,焦点回到输入框。
  • 你放在 leading 和 trailing 插槽中的图标按钮保留自己的名称、角色和焦点停靠点,并按阅读顺序排列。它们不显示在全屏视图的页眉中。
  • 输入、输入法组合、听写和从右到左的文本,都与文本字段中的表现相同。搜索键盘上的操作键会选中活动建议或当前结果;在查询词行上或两者都没有时,提交查询词。
  • 搜索栏用自己的边线显示焦点,无论焦点来自键盘还是指针,与输入框一样。建议行在处于活动状态时,在行内显示焦点环。每一行和搜索栏都达到最小目标。
  • 搜索图标、前置图标和分隔线对辅助技术隐藏。
  • 文本变大时,搜索栏和页眉随之增高,查询词保持在一行之内,建议行会换行。
  • 调试构建会报告:缺少 label、clearLabel 或 backLabel,建议的值为空或重复,标题为空,未知的 presentation、bar 或 status,触发器配停靠的呈现方式,第二个绑定了相同按键的搜索,以及超过两个的后置按钮。

已知的平台差距:

  • SwiftUI、Compose、Flutter 和 React Native 还没有触发器、对话框视图、结果、状态行和快捷键。在这些平台上,请在视图自己的内容中显示结果,并自己朗读结果的数量。
  • SwiftUI、Compose、Flutter 和 React Native 还没有查询词行、行内补全和到两端时的循环。在这些平台上,用户用方向键移到某条建议之前没有活动项,在此之前 Enter 会提交查询词,方向键停在两端。
  • Web:已绑定的快捷键按照其提示所采用的约定来解读 mod,也就是某个祖先元素设置的约定,没有设置时才是平台的约定,而规格只指定了平台的约定。
  • SwiftUI、Compose、Flutter 和 React Native 没有 combobox 或 listbox 角色。它们的输入框是一个搜索框,每条建议是一个带有其在列表中位置的按钮,屏幕阅读器通过轻扫到达它。在这些平台上,活动建议不会作为输入框的活动后代被朗读。Flutter 的建议也没有在列表中的位置,SwiftUI 和 React Native 则用英文说明位置(“2 of 3”;React Native 的 positionText 可以更改它)。
  • Flutter 把输入框作为搜索输入类型暴露,而不是 search box 角色,因为 Flutter 3.32(它支持的最旧版本)不接受这个角色。
  • 在停靠视图之外按下会关闭它。在 Web、SwiftUI、Compose 和 Flutter 上,这次按下还会传到它下方的内容;在 React Native 上不会,与菜单一样。
  • Web:全屏视图页眉的输入框也是 combobox,所以活动建议在那里同样会被朗读。规格只为停靠视图指定了 combobox。
  • Web:停靠视图不会因平台的关闭请求(例如 Android 的返回手势)而关闭。它由脚本定位,而不是像规格中关于 Web 的说明所写的那样用 CSS 锚点定位。
  • 禁用会波及插槽中的图标按钮,而规格让它们保持自己的状态:SwiftUI 的 .disabled(true) 会把它们一并禁用,在 Web 上,小于 1 的禁用不透明度会让它们变淡。每个内置系统的禁用不透明度都是 1。
  • SwiftUI 把停靠视图画在搜索所在容器中排在搜索之后的内容之上,而不是画在窗口中所有视图之上。请让搜索在容器中靠后放置,或者用 zIndex 把它抬高。在 macOS 上不读取窗口的高度,所以视图总是以自然高度在下方打开,全屏视图则是一个与窗口同样大的 sheet。
  • SwiftUI:选区的高亮颜色跟随插入点的着色,而不是文本字段的选区颜色。在没有焦点的输入框上第一次轻点,会把插入点放在查询词的末尾,而不是轻点的位置。按键只在 macOS 上测试过,没有在 iOS 上用硬件键盘测试。
  • Compose 无法区分精确指针和触摸,所以它的建议行高度始终是 48,而 Web 上使用鼠标时是 44。它的测试覆盖不到在停靠视图之外的按下。
  • Flutter:输入框没有焦点时,产品用 expand() 打开的停靠视图不会因在外部按下而关闭。全屏视图需要一个 Navigator;没有它时,视图是停靠的。
  • React Native:停靠视图在打开时以及窗口或键盘变化时定位,但搜索栏滚动时它不会跟随。Escape、方向键和 Tab 只在 TextInput 传递它们的地方才能收到,浮层以及全屏视图的焦点移动还没有在设备上检查过。
  • 在 cupertino 下,搜索栏不画焦点边线,因为 iOS 的搜索框只用插入点和键盘来显示焦点。
  • 在 m3-like 下,搜索按默认系统的值绘制:Material 的搜索取值要等保真度参考覆盖到它。Material 的停靠视图是从搜索栏延伸出来、与它连成一个表面的,这里则画成搜索栏下方的一个独立表面(模仿差距 search-docked-view-joins-bar)。

需要你做的事

  • 给搜索一个 label,并提供 clearLabel,以及用于对话框和全屏视图的 backLabel,都使用你的产品语言。
  • 为当前查询词提供建议,建议的标题要在单独朗读时也能让人明白。
  • 在 statusText 中用你的产品语言说明你的搜索找到了什么,每个答案一次。搜索会朗读它;搜索自己不统计结果数量。
  • 查询由你自己执行,并丢弃乱序到达的答案。
  • 给每个有地址的结果一个 href,它在新的上下文中打开时再给一个 targetLabel。
  • 绑定快捷键的按键,或者设置 bindShortcut。提示的按键如果什么也不做,就会误导用户。
  • 决定 select 做什么;如果选择应当填入查询词,就自己设置查询词。
  • 在 Compose 和 React Native 上,在回调中设置 expanded,否则视图不会打开或关闭。
  • 在 Web 上,给搜索一个 name,以便随表单提交它的查询词。