外观
Combobox 可搜索选择框
在弹层里输入关键字筛选候选项,然后用鼠标或键盘选择一个值。
import { SCombobox } from '@icecreamqaq/shadcn/combobox'使用示例
常用 API
| 成员 | 类型 | 用法 |
|---|---|---|
SCombobox.v-model | AcceptableValue | AcceptableValue[] | 绑定当前选择。启用 multiple 后以数组保存多个值。 |
SCombobox.by | string | 比较函数 | 当选项是对象时,可按稳定属性或比较函数判断两个选项是否相同。 |
SCombobox.v-model:open | boolean | 读取或控制候选列表的开关。 |
SComboboxItem.value | AcceptableValue | 选中后写入模型的值,默认按选项的文本内容进行过滤。 |
SComboboxEmpty | 组件 | 放在 SComboboxList 内,在过滤结果为空时展示提示。 |
完整 API
Combobox35 个成员
属性
| 名称 | 类型 |
|---|---|
open | boolean |
defaultOpen | boolean |
resetSearchTermOnBlur | boolean |
resetSearchTermOnSelect | boolean |
openOnFocus | boolean |
openOnClick | boolean |
ignoreFilter | boolean |
resetModelValueOnClear | boolean |
clearValue | (() => any) |
unmountOnHide | boolean |
asChild | boolean |
as | AsTag | Component |
defaultValue | AcceptableValue | AcceptableValue[] |
modelValue | AcceptableValue | AcceptableValue[] |
by | string | ((a: AcceptableValue, b: AcceptableValue) => boolean) |
dir | Direction |
multiple | boolean |
disabled | boolean |
name | string |
required | boolean |
loop | boolean |
max | number |
highlightOnHover | boolean |
options | readonly SelectEntry[] |
placeholder | string |
search | string |
defaultSearch | string |
renderOption | RenderContent<{ option: SelectOption; }> |
事件
| 名称 | 类型 |
|---|---|
invalid | ((payload: AcceptableValue) => any) |
update:modelValue | ((value: AcceptableValue) => any) |
update:open | ((value: boolean) => any) |
highlight | ((payload: { ref: HTMLElement; value: AcceptableValue; } | undefined) => any) |
update:search | ((value: string) => any) |
插槽
| 名称 | 类型 |
|---|---|
default | ((props: { open: boolean; modelValue: string | number | bigint | Record<string, any> | (string | number | bigint | Record<string, any> | null)[] | null; }) => any) |
empty | ((props: {}) => any) |
ComboboxAnchor5 个成员
属性
| 名称 | 类型 |
|---|---|
reference | ReferenceElement |
asChild | boolean |
as | AsTag | Component |
class | ClassValue |
插槽
| 名称 | 类型 |
|---|---|
default | ((props: {}) => any) |
ComboboxCancel3 个成员
属性
| 名称 | 类型 |
|---|---|
asChild | boolean |
as | AsTag | Component |
插槽
| 名称 | 类型 |
|---|---|
default | ((props: {}) => any) |
ComboboxEmpty4 个成员
属性
| 名称 | 类型 |
|---|---|
asChild | boolean |
as | AsTag | Component |
class | ClassValue |
插槽
| 名称 | 类型 |
|---|---|
default | ((props: {}) => any) |
ComboboxGroup5 个成员
属性
| 名称 | 类型 |
|---|---|
asChild | boolean |
as | AsTag | Component |
class | ClassValue |
heading | string |
插槽
| 名称 | 类型 |
|---|---|
default | ((props: {}) => any) |
ComboboxInput11 个成员
属性
| 名称 | 类型 |
|---|---|
displayValue | ((val: any) => string) |
focusOnOpen | boolean |
modelValue | string |
autoFocus | boolean |
disabled | boolean |
asChild | boolean |
as | AsTag | Component |
class | ClassValue |
defaultValue | string |
事件
| 名称 | 类型 |
|---|---|
update:modelValue | ((args_0: string) => any) |
插槽
| 名称 | 类型 |
|---|---|
default | ((props: {}) => any) |
ComboboxItem8 个成员
属性
| 名称 | 类型 |
|---|---|
textValue | string |
value 必填 | AcceptableValue |
disabled | boolean |
asChild | boolean |
as | AsTag | Component |
class | ClassValue |
事件
| 名称 | 类型 |
|---|---|
select | ((event: CustomEvent<{ originalEvent: PointerEvent; value?: AcceptableValue | undefined; }>) => any) |
插槽
| 名称 | 类型 |
|---|---|
default | ((props: {}) => any) |
ComboboxItemIndicator5 个成员
属性
| 名称 | 类型 |
|---|---|
forceMount | boolean |
asChild | boolean |
as | AsTag | Component |
class | ClassValue |
插槽
| 名称 | 类型 |
|---|---|
default | ((props: {}) => any) |
ComboboxList34 个成员
属性
| 名称 | 类型 |
|---|---|
forceMount | boolean |
position | "popper" | "inline" |
bodyLock | boolean |
hideWhenEmpty | boolean |
memoDependencies | unknown[] |
side | "top" | "right" | "bottom" | "left" |
sideOffset | number |
sideFlip | boolean |
fallbackAxisSideDirection | "none" | "start" | "end" |
align | "start" | "end" | "center" |
alignOffset | number |
alignFlip | boolean |
avoidCollisions | boolean |
collisionBoundary | Element | (Element | null)[] | null |
collisionPadding | number | Partial<Record<"top" | "right" | "bottom" | "left", number>> |
arrowPadding | number |
hideShiftedArrow | boolean |
sticky | "partial" | "always" |
hideWhenDetached | boolean |
positionStrategy | "absolute" | "fixed" |
updatePositionStrategy | "always" | "optimized" |
disableUpdateOnLayoutShift | boolean |
prioritizePosition | boolean |
reference | ReferenceElement |
dir | Direction |
asChild | boolean |
as | AsTag | Component |
disableOutsidePointerEvents | boolean |
class | ClassValue |
事件
| 名称 | 类型 |
|---|---|
escapeKeyDown | ((event: KeyboardEvent) => any) |
pointerDownOutside | ((event: PointerDownOutsideEvent) => any) |
focusOutside | ((event: FocusOutsideEvent) => any) |
interactOutside | ((event: PointerDownOutsideEvent | FocusOutsideEvent) => any) |
插槽
| 名称 | 类型 |
|---|---|
default | ((props: {}) => any) |
ComboboxSeparator4 个成员
属性
| 名称 | 类型 |
|---|---|
asChild | boolean |
as | AsTag | Component |
class | ClassValue |
插槽
| 名称 | 类型 |
|---|---|
default | ((props: {}) => any) |
ComboboxTrigger5 个成员
属性
| 名称 | 类型 |
|---|---|
disabled | boolean |
asChild | boolean |
as | AsTag | Component |
class | ClassValue |
插槽
| 名称 | 类型 |
|---|---|
default | ((props: {}) => any) |
ComboboxViewport5 个成员
属性
| 名称 | 类型 |
|---|---|
nonce | string |
asChild | boolean |
as | AsTag | Component |
class | ClassValue |
插槽
| 名称 | 类型 |
|---|---|
default | ((props: {}) => any) |
分组导出
模板标签为 <s-combobox>。
组件 SCombobox、SComboboxAnchor、SComboboxCancel、SComboboxEmpty、SComboboxGroup、SComboboxInput、SComboboxItem、SComboboxItemIndicator、SComboboxList、SComboboxSeparator、SComboboxTrigger、SComboboxViewport