Combobox

输入时筛选选项列表的文本框,支持分组、空状态、以标签形式多选以及 WAI-ARIA 组合框按键,可作为表单控件。

可用框架
  • Angular: 可用
  • Vue: 可用
  • React: 可用
  • React Native: 可用

用法

LisbonTokyo

导入

ts
import {
  SoneComboboxComponent,
  SoneComboboxInputDirective,
} from "@surface-one/angular/combobox";

API 参考

SoneComboboxComponent组件

`<sone-combobox>` — a text field that filters a listbox of options as you type (shadcn/ui Combobox, spartan/ui Autocomplete; the WAI-ARIA combobox pattern). Up / Down, Home / End and PageUp / PageDown move the highlight (`aria-activedescendant`), Enter picks, Escape closes. `options` holds `{ value, label, disabled, keywords }` or labelled groups of them; `[(value)]` is one value or, with `multiple`, a list shown as removable chips (Backspace removes the last). `[(search)]` is the typed text.

选择器
sone-combobox
输入
名称类型 默认值
options

The options: `{ value, label, disabled?, keywords? }`, or `{ label, options }` groups.

SoneComboboxItems[]
multiple

Pick several options, shown as chips; `value` is then a list.

booleanfalse
value双向

The picked value (`null` while none), or a list with `multiple` — `[(value)]`.

SoneComboboxValuenull
search双向

The typed text — `[(search)]`; it clears when the popup closes.

string""
open双向

The popup is open — `[(open)]`.

booleanfalse
shouldFilter

Filter the options by `search`. Turn off when the options come filtered from a server.

booleantrue
filter

A custom match function (default `soneCommandFilter`: every word, accent-insensitive).

SoneCommandFiltersoneCommandFilter
placeholderstring""
emptyText

Shown in the popup when no option matches.

—$localize`:Combobox empty state:No results found.`
clearable

A clear button while something is picked.

booleanfalse
disabledbooleanfalse
invalidbooleanfalse
inputId

The input's `id`, for a `<label for>`.

string | nullnull
namestring | nullnull
ariaLabel

Names the input when no `<label>` does.

string | nullnull
ariaDescribedby

Extra ids for the input's `aria-describedby`.

string | nullnull
clearLabel—$localize`:Combobox clear button:Clear selection`

SoneComboboxInputDirective指令

`input[soneComboboxInput]` — the combobox's text field and the trigger of its listbox popup, on the popover family's overlay (`SoneOverlayTriggerBase`): the popup renders on `<body>` next to the whole control, closes on Escape and on a click outside, and focus never leaves the input. Used by `sone-combobox`.

选择器
input[soneComboboxInput]
导出为
soneComboboxInput
输入
名称类型 默认值
side

The side of the trigger the panel opens on; it flips when that side lacks room.

FloatingSide"bottom"
align

Alignment along the trigger's edge.

FloatingAlign"start"
offset

Gap between the trigger and the panel, in px.

number4
open双向

Shown or not — `[(open)]`.

booleanfalse
keepOpenOnOutsideClick

Keep the panel open on a click outside it (Escape still closes it).

booleanfalse
soneComboboxInputSoneOverlayContent | nullnull