Combobox
输入时筛选选项列表的文本框,支持分组、空状态、以标签形式多选以及 WAI-ARIA 组合框按键,可作为表单控件。
Angular: 可用 Vue: 可用 React: 可用 React Native: 可用
用法
<div class="demo-row" style="align-items: flex-start; flex-wrap: wrap; min-height: 20rem">
<div soneField style="width: 16rem">
<label soneFieldLabel for="demo-framework">Framework</label>
<sone-combobox inputId="demo-framework" [options]="frameworks" [(value)]="framework" placeholder="Select a framework" clearable />
</div>
<div soneField style="width: 20rem">
<label soneFieldLabel for="demo-cities">Cities</label>
<sone-combobox inputId="demo-cities" [options]="cities" [(value)]="picked" multiple placeholder="Add a city" />
</div>
</div>导入
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.
| 名称 | 类型 | 默认值 |
|---|---|---|
optionsThe options: `{ value, label, disabled?, keywords? }`, or `{ label, options }` groups. | SoneComboboxItems | [] |
multiplePick several options, shown as chips; `value` is then a list. | boolean | false |
value双向The picked value (`null` while none), or a list with `multiple` — `[(value)]`. | SoneComboboxValue | null |
search双向The typed text — `[(search)]`; it clears when the popup closes. | string | "" |
open双向The popup is open — `[(open)]`. | boolean | false |
shouldFilterFilter the options by `search`. Turn off when the options come filtered from a server. | boolean | true |
filterA custom match function (default `soneCommandFilter`: every word, accent-insensitive). | SoneCommandFilter | soneCommandFilter |
placeholder | string | "" |
emptyTextShown in the popup when no option matches. | — | $localize`:Combobox empty state:No results found.` |
clearableA clear button while something is picked. | boolean | false |
disabled | boolean | false |
invalid | boolean | false |
inputIdThe input's `id`, for a `<label for>`. | string | null | null |
name | string | null | null |
ariaLabelNames the input when no `<label>` does. | string | null | null |
ariaDescribedbyExtra ids for the input's `aria-describedby`. | string | null | null |
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`.
| 名称 | 类型 | 默认值 |
|---|---|---|
sideThe side of the trigger the panel opens on; it flips when that side lacks room. | FloatingSide | "bottom" |
alignAlignment along the trigger's edge. | FloatingAlign | "start" |
offsetGap between the trigger and the panel, in px. | number | 4 |
open双向Shown or not — `[(open)]`. | boolean | false |
keepOpenOnOutsideClickKeep the panel open on a click outside it (Escape still closes it). | boolean | false |
soneComboboxInput | SoneOverlayContent | null | null |