组件 · 搜索
Search
The search trigger in the web top bar, and the parts of search results — rows for places and people, message and thread hits, grouped by kind with the matched words marked.
import { Search } from "@botiverse/raft-ui";Search is a field, a few filters and results grouped by kind. Places and people are rows; messages are hits that say who, where and when, with the matched words as small yellow stickers. On the web, search opens from the search field in the top bar (SearchTrigger); on a phone it is the Search tab, with the field in the tab's top bar.
When to use
| Situation | Use |
|---|---|
| Finding a place, a person or a message to go to | Search |
| Finding a value to fill in, inside a popup | A select with search (ComboboxSelect) or a Combobox |
| Narrowing a list that is already on screen | A filter (Choosing a component) |
Anatomy
Trigger
SearchTrigger: the top bar's search field. It looks like a field and is a button that opens the search dialog. Like every field it doesn't hover; a press lays the medium tier (Hover and press).- A search icon, then
SearchTriggerLabel(the placeholder, Search Raft), thenSearchTriggerShortcut(⌘K) at the right end. The label truncates first.
- A search icon, then
Results
SearchShellRoot: the search surface, withSearchShellFilters(the row of filters) andSearchShellViewport(the scrolling results).SearchResultsSummary: one line about the results: "Searching for “launch”…".SearchResultsSection: one kind of result, withSearchResultsSectionHeading(Messages 13) andSearchResultsList.SearchEntityResult: a channel, a person or an agent. It follows the layout of a ListRow:SearchEntityResultLeading(aSearchEntityResultIconor an avatar, with an optionalSearchEntityResultActivitylight), andSearchEntityResultContentwithSearchEntityResultHeader,SearchEntityResultTitleandSearchEntityResultDescription.SearchMessageResult: a message.SearchMessageResultHeaderholdsSearchMessageResultSender(who),SearchMessageResultMeta(where),SearchMessageResultThreadMeta(in a thread) andSearchMessageResultTimestamp(when);SearchMessageResultBodyholds the excerpt, with each match inSearchMessageResultMatch.SearchThreadResult: a thread with several hits:SearchThreadResultHeader(SearchThreadResultMeta,SearchThreadResultTimestamp,SearchThreadResultTitle) andSearchThreadResultMessages, a list ofSearchThreadMessageResult.
States
| State | Use for |
|---|---|
selected on a result | The keyboard highlight: brand-soft, as in menus (States) |
Menu open (data-popup-open on a result) | fill-subtle, the same subtle tier as the hover, so the result the menu acts on stays marked; a selected result keeps brand-soft (Hover and press) |
muted on an entity's title and description | A place the person can't post in any more, such as an archived channel |
| Loading | A summary line and skeletons in the shape of the results (Feedback) |
| No results | An EmptyState that says how to widen the search |
Behavior
- On a phone, search is the Search tab, and the field is in its navigation row (Page structure). Its keyboard, its kept state, opening a result and searching inside one place are in Navigation.
- Give the field the same margin on both sides, the content edge of what is under it (16px on a phone). Don't leave a narrower edge on one side for an icon.
- On the web, open search from the top bar's field as a centered dialog, 720px wide, whose top edge covers the top bar's field, so the field seems to grow into it. It has the scrim and no animation, like every centered overlay (Choosing a component).
- Group results by kind (Conversation): places and people first, then messages.
- Show the scope, the sender, the place and the time range as filters in the filter row, each a select or combobox.
- Open a selected result in the side panel (Conversation). A hit in a thread opens that thread directly.
- Move the keyboard highlight from the field into the results with the Down arrow, and open the highlighted result with Enter.
Content
- Make the excerpt of a message at most 2 lines, with the matched words in
SearchMessageResultMatch. - Write the no-results state as what wasn't found and how to widen it: "No results for “launch”", "Try another word or remove a filter."
- Write the trigger's placeholder as what it searches: Search Raft.
Accessibility
- The parts render native elements through Base UI's
useRender; no Base UI primitive is involved. Results arebuttons by default; pass a link withrenderfor a result that navigates. SearchTriggeris abuttonnamed by its label. It opens a Dialog; give the dialog a title and the field inside it an accessible name (aria-label="Search").- Put the field and its filters in an element with
role="search", and give the clear buttonaria-label="Clear search". selectedis visual only. When you move a keyboard highlight through the results, keep focus on the field and point to the highlighted result witharia-activedescendant, or move focus to it.- Give an entity's activity light a name:
role="img"andaria-label="Active". SearchMessageResultMatchis amark, so matches are announced where the reader supports it.
API
SearchShellRoot
| Prop | 类型 | 默认值 |
|---|---|---|
| PanelEdge | "inset" | |
| Allows you to replace the component's HTML element with a different tag, or compose it with another component. | ReactElement | ((props, state) => ReactElement) |
Also takes the attributes of its element.
SearchShellFilters, SearchShellViewport
接受其元素的全部属性。
SearchResultsSummary, SearchResultsSection, SearchResultsSectionHeading, SearchResultsList
| Prop | 类型 | 默认值 |
|---|---|---|
| Allows you to replace the component's HTML element with a different tag, or compose it with another component. | ReactElement | ((props, state) => ReactElement) |
Also takes the attributes of its element.
SearchEntityResult
| Prop | 类型 | 默认值 |
|---|---|---|
| boolean | false | |
| Allows you to replace the component's HTML element with a different tag, or compose it with another component. | ReactElement | ((props, state) => ReactElement) |
Also takes the attributes of its element.
SearchEntityResultContent, SearchEntityResultHeader, SearchEntityResultLeading, SearchEntityResultIcon, SearchEntityResultActivity
| Prop | 类型 | 默认值 |
|---|---|---|
| Allows you to replace the component's HTML element with a different tag, or compose it with another component. | ReactElement | ((props, state) => ReactElement) |
Also takes the attributes of its element.
SearchEntityResultTitle, SearchEntityResultDescription
| Prop | 类型 | 默认值 |
|---|---|---|
| boolean | false | |
| Allows you to replace the component's HTML element with a different tag, or compose it with another component. | ReactElement | ((props, state) => ReactElement) |
Also takes the attributes of its element.
SearchMessageResult, SearchThreadMessageResult
| Prop | 类型 | 默认值 |
|---|---|---|
| boolean | ||
| Allows you to replace the component's HTML element with a different tag, or compose it with another component. | ReactElement | ((props, state) => ReactElement) |
Also takes the attributes of its element.
SearchMessageResultHeader, SearchMessageResultBody, SearchMessageResultMeta, SearchMessageResultThreadMeta, SearchMessageResultSender, SearchMessageResultTimestamp, SearchMessageResultMatch
| Prop | 类型 | 默认值 |
|---|---|---|
| Allows you to replace the component's HTML element with a different tag, or compose it with another component. | ReactElement | ((props, state) => ReactElement) |
Also takes the attributes of its element.
SearchThreadResult
| Prop | 类型 | 默认值 |
|---|---|---|
| boolean | false | |
| Allows you to replace the component's HTML element with a different tag, or compose it with another component. | ReactElement | ((props, state) => ReactElement) |
Also takes the attributes of its element.
SearchThreadResultHeader, SearchThreadResultMeta, SearchThreadResultTimestamp, SearchThreadResultTitle, SearchThreadResultMessages, SearchTrigger, SearchTriggerLabel
| Prop | 类型 | 默认值 |
|---|---|---|
| Allows you to replace the component's HTML element with a different tag, or compose it with another component. | ReactElement | ((props, state) => ReactElement) |
Also takes the attributes of its element.
SearchTriggerShortcut
接受其元素的全部属性。
相关组件
改动
- 0.10.0 · Breaking ChangesField frames (
Input,Textarea,InputGroup,Select,Combobox,ComboboxSelect,Composer, optionCard,SearchTrigger) are drawn at 1px inline-fieldinstead of 1.5px, on the phone too. - 0.6.1 · Added
SearchTrigger(SearchTriggerLabel,SearchTriggerShortcut): the web top bar's search box, a button drawn as a field.