Morphing Search

将搜索框展开为建议、最近记录或可编辑筛选标签。

适用场景

  • 当界面需要以下行为时使用 Morphing Search:将搜索框展开为建议、最近记录或可编辑筛选标签。

安装

选择安装方式,用法示例将同步更新导入路径。

$ bunx --bun shadcn-vue@2.8.2 add https://orvui.efu.me/r/morphing-search.json https://orvui.efu.me/r/morphing-search-chips.json

首次使用时,将安装的 src/components/orvui/styles.css 导入项目样式入口。

示例

Chip Search

chips.vue

将提交的词语转换为可移除标签,搜索表面围绕标签展开。

onboarding
Enter adds a filter. Backspace at the start of the field selects the last filter, and again removes it. Delete removes the highlighted recent search.

Morphing Search

overlay.vue

通过指针或键盘,从输入框或紧凑触发器打开较大的搜索表面。

状态与事件

需要由表单、路由或父组件管理时,绑定下列状态并接收对应更新。v-model 是属性与 update 事件的简写;值的类型应与 API 一致。

组件状态绑定
组件Vue 绑定更新事件
MorphingSearchv-model:openbooleanupdate:open
MorphingSearchChipsv-model:chipsstring[]update:chips
MorphingSearchChipsv-model:querystringupdate:query
MorphingSearchChipsv-model:recentsstring[]update:recents
MorphingSearchChipsv-model:openbooleanupdate:open

可选受控属性未传入时,按组件文档的默认行为工作;不要用固定的 false 或空值代替未传入。异步请求和持久化在应用中处理,再把结果传回组件。

API 参考

Chip Search

chips?
string[]
—
defaultChips?
string[]
() => []
query?
string
—
defaultQuery?
string
""
recents?
string[]
localRecents.value
defaultRecents?
string[]
() => []
storageKey?
string
—
maxRecents?
number
5
suggestions?
string[]
() => []
filter?
false | (term: string, query: string) => boolean
undefined
maxSuggestions?
number
6
loading?
boolean
false
maxChips?
number
—
normalize?
(term: string) => string | null
—
emptyState?
boolean | null | string | number | void | VNode<RendererNode, RendererElement, { [key: string]: any; }> | VNodeArrayChildren | ComponentOptions<any, any, any, ComputedOptions, MethodOptions, any, any, any, string, {}, {}, string, {}, {}, {}, string, ComponentProvideOptions> | FunctionalComponent<any, {}, any, {}> | ComponentPublicInstanceConstructor<any, any, any, any, ComputedOptions, MethodOptions>
undefined
side?
"top" | "bottom" | "auto"
"top"
open?
boolean
undefined
defaultOpen?
boolean
false
disabled?
boolean
false
name?
string
—
placeholder?
string
"Search"
label?
string
"Search"
actions?
boolean | null | string | number | void | VNode<RendererNode, RendererElement, { [key: string]: any; }> | VNodeArrayChildren | ComponentOptions<any, any, any, ComputedOptions, MethodOptions, any, any, any, string, {}, {}, string, {}, {}, {}, string, ComponentProvideOptions> | FunctionalComponent<any, {}, any, {}> | ComponentPublicInstanceConstructor<any, any, any, any, ComputedOptions, MethodOptions>
undefined

事件

update:chips
[chips: string[]]
@update:chips
chipsChange
[chips: string[]]
@chipsChange
update:query
[query: string]
@update:query
queryChange
[query: string]
@queryChange
update:recents
[recents: string[]]
@update:recents
recentsChange
[recents: string[]]
@recentsChange
update:open
[open: boolean]
@update:open
openChange
[open: boolean]
@openChange

插槽

empty
() => VNodeChild
#empty
actions
() => VNodeChild
#actions

Morphing Search

items
MorphingSearchItem[]
—
placeholder?
string
"Search"
shortcut?
string
"f"
iconOnly?
boolean
false
emptyMessage?
string
"No results found."
open?
boolean
undefined
defaultOpen?
boolean
false

事件

update:open
[open: boolean]
@update:open
openChange
[open: boolean]
@openChange
queryChange
[query: string]
@queryChange
select
[item: MorphingSearchItem]
@select

无障碍

为交互控件提供明确的无障碍名称。保留文档中的键盘路径、可见焦点与减少动态效果状态;自定义插槽应继续保留所替代部件的语义。

常见问题

如何配置 Morphing Search?
通过 items、placeholder、shortcut、iconOnly、emptyMessage、open、defaultOpen 配置 Morphing Search;API 表列出其类型与默认值。
如何连接到应用状态?
监听 update:open、openChange、queryChange、select,将组件连接到应用状态。
可以在服务端渲染吗?
可以在 Vue SSR 应用中正常渲染。服务端与客户端的初始 props 应保持一致;浏览器测量与交互资源在挂载后启动。

请留意

部分组件参考了开源作品,相关署名与独立许可请参阅 NOTICE。

更新于