@aircall/ds 0.49.0 → 0.50.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{data-table-B3ahtFLP.js → data-table-AX0Mgu6K.js} +5 -0
- package/dist/{data-table-BgeS8KWP.d.ts → data-table-B5VqWPmw.d.ts} +3 -4
- package/dist/data-table.d.ts +1 -1
- package/dist/data-table.js +1 -1
- package/dist/globals.css +1 -1
- package/dist/index.d.ts +53 -16
- package/dist/index.js +113 -20
- package/package.json +2 -2
- package/skills/aircall-ds/migrate-audio-player/SKILL.md +14 -3
- package/skills/aircall-ds/migrate-icons/SKILL.md +45 -16
- package/skills/aircall-ds/migrate-tractor/SKILL.md +34 -31
- package/skills/aircall-ds/migrate-tractor/accordion/SKILL.md +25 -15
- package/skills/aircall-ds/migrate-tractor/alert/SKILL.md +107 -20
- package/skills/aircall-ds/migrate-tractor/avatar/SKILL.md +57 -26
- package/skills/aircall-ds/migrate-tractor/badge/SKILL.md +71 -25
- package/skills/aircall-ds/migrate-tractor/button/SKILL.md +68 -32
- package/skills/aircall-ds/migrate-tractor/card/SKILL.md +62 -42
- package/skills/aircall-ds/migrate-tractor/combobox/SKILL.md +233 -149
- package/skills/aircall-ds/migrate-tractor/data-table/SKILL.md +102 -108
- package/skills/aircall-ds/migrate-tractor/data-table/references/column-widths-and-pinning.md +50 -0
- package/skills/aircall-ds/migrate-tractor/data-table/references/infinite-scroll.md +51 -0
- package/skills/aircall-ds/migrate-tractor/data-table/references/row-actions.md +34 -0
- package/skills/aircall-ds/migrate-tractor/date-picker/SKILL.md +100 -47
- package/skills/aircall-ds/migrate-tractor/dialog/SKILL.md +115 -20
- package/skills/aircall-ds/migrate-tractor/dropdown-menu/SKILL.md +135 -57
- package/skills/aircall-ds/migrate-tractor/dropzone/SKILL.md +2 -0
- package/skills/aircall-ds/migrate-tractor/form-and-field/SKILL.md +111 -49
- package/skills/aircall-ds/migrate-tractor/gauge/SKILL.md +6 -4
- package/skills/aircall-ds/migrate-tractor/input/SKILL.md +165 -59
- package/skills/aircall-ds/migrate-tractor/item/SKILL.md +85 -63
- package/skills/aircall-ds/migrate-tractor/link/SKILL.md +85 -68
- package/skills/aircall-ds/migrate-tractor/popover/SKILL.md +115 -74
- package/skills/aircall-ds/migrate-tractor/select/SKILL.md +117 -64
- package/skills/aircall-ds/migrate-tractor/sheet-vs-drawer/SKILL.md +55 -32
- package/skills/aircall-ds/migrate-tractor/skeleton/SKILL.md +40 -11
- package/skills/aircall-ds/migrate-tractor/styling/SKILL.md +11 -7
- package/skills/aircall-ds/migrate-tractor/tabs/SKILL.md +62 -55
- package/skills/aircall-ds/migrate-tractor/toast/SKILL.md +58 -12
- package/skills/aircall-ds/migrate-tractor/tooltip/SKILL.md +65 -40
- package/skills/aircall-ds/migrate-tractor/tree/SKILL.md +23 -6
- package/skills/aircall-ds/setup/SKILL.md +53 -8
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: aircall-ds/migrate-tractor/combobox
|
|
3
3
|
description: >
|
|
4
|
-
Migrate Tractor ComboBox (
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
Migrate Tractor ComboBox (ComboBox, ComboBoxTrigger, ComboBoxContent, ComboBoxMenu,
|
|
5
|
+
ComboBoxItem) and hand-rolled Command + Popover search combos to the @aircall/ds
|
|
6
|
+
Combobox compound or the data-driven DataCombobox. Load when a file imports ComboBox
|
|
7
|
+
from @aircall/tractor, or builds a search-and-pick list from Command + Popover.
|
|
7
8
|
type: sub-skill
|
|
8
9
|
library: aircall-ds
|
|
9
10
|
requires:
|
|
@@ -11,6 +12,11 @@ requires:
|
|
|
11
12
|
- aircall-ds/migrate-tractor
|
|
12
13
|
sources:
|
|
13
14
|
- "aircall/hydra:docs/migration-guides/tractor-to-ds/recipes/combobox.md"
|
|
15
|
+
- "aircall/hydra:packages/ds/src/components/combobox.tsx"
|
|
16
|
+
- "aircall/hydra:packages/ds/src/components/data-combobox.tsx"
|
|
17
|
+
- "aircall/hydra:packages/ds/src/recipes/combobox-multi-select.tsx"
|
|
18
|
+
- "aircall/hydra:packages/ds/src/stories/Combobox.stories.tsx"
|
|
19
|
+
- "aircall/hydra:packages/ds/src/stories/DataCombobox.stories.tsx"
|
|
14
20
|
---
|
|
15
21
|
|
|
16
22
|
This skill builds on aircall-ds/migrate-tractor. Apply all cross-cutting rules from that skill (prop renames, `render` prop, data attributes) before the combobox-specific steps below.
|
|
@@ -21,28 +27,30 @@ Use `Combobox` when the user needs to **search or filter** options. For a short,
|
|
|
21
27
|
|
|
22
28
|
**Two tiers** (same split as `Table`/`DataTable`):
|
|
23
29
|
|
|
24
|
-
- **`DataCombobox`** — batteries-included, data-driven. Give it an `items` array plus `getItemValue`/`getItemLabel` accessors and it owns selection state, search, infinite scroll, and loading states. **Prefer it** for anything async (search-as-you-type, paginated, loading) — see §5c
|
|
30
|
+
- **`DataCombobox`** — batteries-included, data-driven. Give it an `items` array plus `getItemValue`/`getItemLabel` accessors and it owns selection state, search, infinite scroll, virtualization, and loading states. **Prefer it** for anything async (search-as-you-type, paginated, loading) — see §5c — and for a straight port of Tractor's key-based `selectedKeys`/`onSelectionChange`.
|
|
25
31
|
- **`Combobox` primitives** (compound) — full markup control for static/bespoke cases. Covered by the mapping and examples §2–§5b, and the full-control async fallback §5d.
|
|
26
32
|
|
|
33
|
+
If the project also uses `@aircall/blocks`, a country, language or timezone picker is already built: `CountryCombobox`, `LanguageCombobox` (`multiple` for several), `TimezoneCombobox`. A combobox that lives in a page filter row is `FilterCombobox`. Use those instead of re-assembling the list.
|
|
34
|
+
|
|
27
35
|
## 2. Component mapping
|
|
28
36
|
|
|
29
|
-
Tractor `ComboBox` was a
|
|
37
|
+
Tractor `ComboBox` was a compound of its own: `ComboBox` (state, `selectionMode`, `selectedKeys: K[]`) wrapping a `ComboBoxTrigger` (any element, usually a `TextInput` or a tags field) and a `ComboBoxContent` > `ComboBoxMenu` > `ComboBoxItem itemKey`. Search input, tags and clear buttons were all hand-built. DS makes every slot a named part, and the old "Command + Popover" search recipe is fully replaced by the same compound.
|
|
30
38
|
|
|
31
39
|
| Tractor / old pattern | DS compound part | Role |
|
|
32
40
|
| --- | --- | --- |
|
|
33
|
-
| `<ComboBox>` | `<Combobox>` | State owner (`value`, `onValueChange`, `multiple`) |
|
|
34
|
-
|
|
|
35
|
-
|
|
|
36
|
-
|
|
|
37
|
-
|
|
|
38
|
-
| `<
|
|
39
|
-
|
|
|
40
|
-
| _(
|
|
41
|
-
| _(no equivalent)_ | `<ComboboxLabel>` |
|
|
42
|
-
|
|
|
43
|
-
|
|
|
44
|
-
| _(no equivalent)_ |
|
|
45
|
-
|
|
|
41
|
+
| `<ComboBox selectionMode selectedKeys onSelectionChange>` | `<Combobox>` | State owner (`items`, `value`, `onValueChange`, `multiple`) |
|
|
42
|
+
| `<ComboBoxTrigger><TextInput …/></ComboBoxTrigger>` (single) | `<ComboboxInput>` | Visible text field; trailing chevron on by default (`showTrigger`), optional clear (`showClear`, off by default) |
|
|
43
|
+
| `<ComboBoxTrigger><ComboBoxTags …/></ComboBoxTrigger>` (multi) | `<ComboboxChips>` + `<ComboboxChip>` + `<ComboboxChipsInput>` | Chips field with its own chevron (`showTrigger`) |
|
|
44
|
+
| a custom trigger button | `<ComboboxTrigger>` | Button with a chevron; put the search `ComboboxInput` inside `ComboboxContent` (see the `combobox-dropdown-search` recipe) |
|
|
45
|
+
| `<ComboBoxContent>` | `<ComboboxContent>` | Popover container — handles portal + positioning |
|
|
46
|
+
| `<ComboBoxMenu>` | `<ComboboxList>` | Scrollable list; receives the render function that maps `items` |
|
|
47
|
+
| `<ComboBoxItem itemKey>` / `<CommandItem>` | `<ComboboxItem value>` | Individual option (trailing check indicator built in) |
|
|
48
|
+
| _(not built in)_ | `<ComboboxEmpty>` | Shown when the filtered list is empty. Sits in `ComboboxContent` next to `ComboboxList` |
|
|
49
|
+
| _(no equivalent)_ | `<ComboboxGroup>` + `<ComboboxLabel>` + `<ComboboxCollection>` + `<ComboboxSeparator>` | Sections (label must be inside the group) |
|
|
50
|
+
| `useComboBox()` (`selectedKeys`, `removeKey`, `removeAll`) | `<ComboboxValue>` render function, chip remove button, `showClear` | Read the selection inside `ComboboxChips`; chips remove themselves |
|
|
51
|
+
| `MenuItemPrefix` / `MenuItemLabel` / `MenuItemDescription` / `MenuItemSuffix` inside an item | children of `ComboboxItem` | Rich rows: compose the `Item` primitives at `size="xs"` (see `RichItems` story) |
|
|
52
|
+
| _(no equivalent)_ | `useComboboxAnchor()` | Returns a ref that anchors `ComboboxContent` to the chips container |
|
|
53
|
+
| `ComboBox` + async fetching by hand | `<DataCombobox>` | See §5c |
|
|
46
54
|
|
|
47
55
|
## 3. Verified DS exports (`packages/ds/src/index.ts`)
|
|
48
56
|
|
|
@@ -52,20 +60,26 @@ ComboboxCollection, ComboboxContent, ComboboxEmpty, ComboboxGroup,
|
|
|
52
60
|
ComboboxInput, ComboboxItem, ComboboxLabel, ComboboxList,
|
|
53
61
|
ComboboxSeparator, ComboboxTrigger, ComboboxValue,
|
|
54
62
|
useComboboxAnchor,
|
|
55
|
-
DataCombobox
|
|
63
|
+
DataCombobox, COMBOBOX_AUTO_SEARCH_THRESHOLD, COMBOBOX_AUTO_VIRTUALIZE_THRESHOLD,
|
|
64
|
+
type ComboboxLoadingState, type ComboboxSelectionChangeDetails,
|
|
65
|
+
type ComboboxClear // type only — not a component value
|
|
56
66
|
```
|
|
57
67
|
|
|
58
|
-
All names used in the Before/After examples below exist in the published public API.
|
|
68
|
+
All names used in the Before/After examples below exist in the published public API. `ComboboxMultiSelect`, `ComboboxSearchableSelect` and `ComboboxDropdownSearch` are copy-paste **recipes** (`pnpm dlx shadcn@latest add https://ds.aircall.io/r/<name>.json`), not exports.
|
|
59
69
|
|
|
60
70
|
## 4. Key prop differences
|
|
61
71
|
|
|
62
72
|
| Tractor / old pattern | DS equivalent | Notes |
|
|
63
73
|
| --- | --- | --- |
|
|
64
|
-
| `
|
|
65
|
-
| `
|
|
66
|
-
| `
|
|
67
|
-
|
|
|
68
|
-
| `
|
|
74
|
+
| `selectionMode="multiple"` | `multiple` on `<Combobox>` | Boolean flag; `value`/`onValueChange` then carry an array |
|
|
75
|
+
| `selectedKeys: K[]` / `defaultSelectedKeys` | `value` / `defaultValue` | On the primitives the value is the **item** (an object, or a string if `items` is a string array). `DataCombobox` keeps keys: `selectedKeys: Set<string>` |
|
|
76
|
+
| `onSelectionChange(keys: K[])` | `onValueChange(value, eventDetails)` | `string \| T \| null` for single (`null` when cleared); `T[]` for multiple. `DataCombobox`: `onSelectionChange(keys: Set<string>, details)` |
|
|
77
|
+
| `itemKey` on `ComboBoxItem` | `value` on `ComboboxItem` | Pass the same value that is in `items` |
|
|
78
|
+
| `open` / `defaultOpen` / `onOpen` / `onClose` | `open` / `defaultOpen` / `onOpenChange(open, details)` | One callback; read `details.reason` (`'escape-key'`, `'item-press'`, …) when a dismissal and a pick must differ |
|
|
79
|
+
| `disabled` on `ComboBox` / `ComboBoxItem` | `disabled` on `<Combobox>` / `<ComboboxItem>` | `DataCombobox` also takes `disabledKeys: Set<string>` |
|
|
80
|
+
| `TextInput onClear` in the trigger | `showClear` on `<ComboboxInput>` | Single-select only; renders the X button |
|
|
81
|
+
| search `TextInput` you filtered by hand | built-in filtering | Base UI filters `items` against the typed text. Opt out for server search with `filter={null}` (primitives) or `onSearch` (`DataCombobox`) |
|
|
82
|
+
| `closeOnInsideClick={false}` on `ComboBoxContent` | _(drop it)_ | Multi-select behaviour is decided by `multiple`; no per-click close flag |
|
|
69
83
|
|
|
70
84
|
## 5. Before / After
|
|
71
85
|
|
|
@@ -74,18 +88,24 @@ All names used in the Before/After examples below exist in the published public
|
|
|
74
88
|
#### Before (Tractor)
|
|
75
89
|
|
|
76
90
|
```tsx
|
|
77
|
-
import { ComboBox,
|
|
78
|
-
|
|
79
|
-
<
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
>
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
91
|
+
import { ComboBox, ComboBoxContent, ComboBoxItem, ComboBoxMenu, ComboBoxTrigger, TextInput } from '@aircall/tractor';
|
|
92
|
+
|
|
93
|
+
const [selected, setSelected] = React.useState<string[]>([]);
|
|
94
|
+
const label = countries.find(c => c.iso === selected[0])?.name ?? '';
|
|
95
|
+
|
|
96
|
+
<ComboBox selectionMode="single" selectedKeys={selected} onSelectionChange={setSelected}>
|
|
97
|
+
<ComboBoxTrigger>
|
|
98
|
+
<TextInput readOnly onClear={() => setSelected([])} value={label} placeholder="Search countries" />
|
|
99
|
+
</ComboBoxTrigger>
|
|
100
|
+
<ComboBoxContent>
|
|
101
|
+
<ComboBoxMenu py="8px">
|
|
102
|
+
{countries.map(c => (
|
|
103
|
+
<ComboBoxItem itemKey={c.iso} key={c.iso}>
|
|
104
|
+
{c.name}
|
|
105
|
+
</ComboBoxItem>
|
|
106
|
+
))}
|
|
107
|
+
</ComboBoxMenu>
|
|
108
|
+
</ComboBoxContent>
|
|
89
109
|
</ComboBox>
|
|
90
110
|
```
|
|
91
111
|
|
|
@@ -96,49 +116,62 @@ import {
|
|
|
96
116
|
Combobox,
|
|
97
117
|
ComboboxContent,
|
|
98
118
|
ComboboxEmpty,
|
|
99
|
-
ComboboxGroup,
|
|
100
119
|
ComboboxInput,
|
|
101
120
|
ComboboxItem,
|
|
102
|
-
ComboboxLabel,
|
|
103
121
|
ComboboxList,
|
|
104
122
|
} from '@aircall/ds';
|
|
105
123
|
|
|
106
|
-
|
|
107
|
-
|
|
124
|
+
// `{ value, label }` items: Base UI reads the label for the input text and the filter.
|
|
125
|
+
type Country = { value: string; label: string };
|
|
126
|
+
const items: Country[] = countries.map(c => ({ value: c.iso, label: c.name }));
|
|
127
|
+
|
|
128
|
+
const [country, setCountry] = React.useState<Country | null>(null);
|
|
129
|
+
|
|
130
|
+
<Combobox items={items} value={country} onValueChange={setCountry}>
|
|
131
|
+
<ComboboxInput placeholder="Search countries" showClear />
|
|
108
132
|
<ComboboxContent>
|
|
133
|
+
<ComboboxEmpty>No results.</ComboboxEmpty>
|
|
109
134
|
<ComboboxList>
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
{c.name}
|
|
116
|
-
</ComboboxItem>
|
|
117
|
-
))}
|
|
118
|
-
</ComboboxGroup>
|
|
135
|
+
{(c: Country) => (
|
|
136
|
+
<ComboboxItem key={c.value} value={c}>
|
|
137
|
+
{c.label}
|
|
138
|
+
</ComboboxItem>
|
|
139
|
+
)}
|
|
119
140
|
</ComboboxList>
|
|
120
141
|
</ComboboxContent>
|
|
121
142
|
</Combobox>
|
|
122
143
|
```
|
|
123
144
|
|
|
145
|
+
The compound needs `items` on the root plus a render function on `ComboboxList`: that is what lets Base UI filter, drive `ComboboxEmpty`, and handle keyboard navigation (see Mistake 3). To keep Tractor's key-based state (`Set<string>` of ids) instead of the item object, use `DataCombobox` (§5c).
|
|
146
|
+
|
|
124
147
|
### 5b. Multi-select with chips
|
|
125
148
|
|
|
126
|
-
#### Before (Tractor
|
|
149
|
+
#### Before (Tractor)
|
|
127
150
|
|
|
128
151
|
```tsx
|
|
129
|
-
import { ComboBox } from '@aircall/tractor';
|
|
130
|
-
|
|
131
|
-
<
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
152
|
+
import { ComboBox, ComboBoxContent, ComboBoxItem, ComboBoxMenu, ComboBoxTrigger } from '@aircall/tractor';
|
|
153
|
+
|
|
154
|
+
// ComboBoxTags was a story-local helper reading useComboBox(): a Flex of <Tag>s with a clear icon
|
|
155
|
+
<ComboBox selectionMode="multiple" selectedKeys={selected} onSelectionChange={setSelected}>
|
|
156
|
+
<ComboBoxTrigger>
|
|
157
|
+
<ComboBoxTags options={options} />
|
|
158
|
+
</ComboBoxTrigger>
|
|
159
|
+
<ComboBoxContent closeOnInsideClick={false}>
|
|
160
|
+
<ComboBoxMenu py="8px">
|
|
161
|
+
{options.map(({ value, label }) => (
|
|
162
|
+
<ComboBoxItem itemKey={value} key={value}>
|
|
163
|
+
{label}
|
|
164
|
+
</ComboBoxItem>
|
|
165
|
+
))}
|
|
166
|
+
</ComboBoxMenu>
|
|
167
|
+
</ComboBoxContent>
|
|
168
|
+
</ComboBox>
|
|
138
169
|
```
|
|
139
170
|
|
|
140
171
|
#### After (DS)
|
|
141
172
|
|
|
173
|
+
This is the `combobox-multi-select` recipe (`packages/ds/src/recipes/combobox-multi-select.tsx`).
|
|
174
|
+
|
|
142
175
|
```tsx
|
|
143
176
|
import {
|
|
144
177
|
Combobox,
|
|
@@ -149,31 +182,45 @@ import {
|
|
|
149
182
|
ComboboxEmpty,
|
|
150
183
|
ComboboxItem,
|
|
151
184
|
ComboboxList,
|
|
185
|
+
ComboboxValue,
|
|
152
186
|
useComboboxAnchor,
|
|
153
187
|
} from '@aircall/ds';
|
|
154
188
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
189
|
+
type Option = { value: string; label: string };
|
|
190
|
+
|
|
191
|
+
function TagPicker({ options }: { options: Option[] }) {
|
|
192
|
+
const [selected, setSelected] = React.useState<Option[]>([]);
|
|
193
|
+
const anchor = useComboboxAnchor();
|
|
158
194
|
|
|
159
195
|
return (
|
|
160
|
-
<Combobox
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
196
|
+
<Combobox
|
|
197
|
+
multiple
|
|
198
|
+
autoHighlight
|
|
199
|
+
items={options}
|
|
200
|
+
itemToStringValue={(item: Option) => item.value}
|
|
201
|
+
value={selected}
|
|
202
|
+
onValueChange={setSelected}
|
|
203
|
+
>
|
|
204
|
+
<ComboboxChips ref={anchor}>
|
|
205
|
+
<ComboboxValue>
|
|
206
|
+
{(values: Option[]) => (
|
|
207
|
+
<>
|
|
208
|
+
{values.map(v => (
|
|
209
|
+
<ComboboxChip key={v.value}>{v.label}</ComboboxChip>
|
|
210
|
+
))}
|
|
211
|
+
<ComboboxChipsInput placeholder={values.length === 0 ? 'Add a tag' : ''} />
|
|
212
|
+
</>
|
|
213
|
+
)}
|
|
214
|
+
</ComboboxValue>
|
|
168
215
|
</ComboboxChips>
|
|
169
|
-
<ComboboxContent anchor={
|
|
216
|
+
<ComboboxContent anchor={anchor}>
|
|
217
|
+
<ComboboxEmpty>No results.</ComboboxEmpty>
|
|
170
218
|
<ComboboxList>
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
<ComboboxItem key={item.value} value={item.value}>
|
|
219
|
+
{(item: Option) => (
|
|
220
|
+
<ComboboxItem key={item.value} value={item}>
|
|
174
221
|
{item.label}
|
|
175
222
|
</ComboboxItem>
|
|
176
|
-
)
|
|
223
|
+
)}
|
|
177
224
|
</ComboboxList>
|
|
178
225
|
</ComboboxContent>
|
|
179
226
|
</Combobox>
|
|
@@ -181,13 +228,18 @@ function TagPicker() {
|
|
|
181
228
|
}
|
|
182
229
|
```
|
|
183
230
|
|
|
231
|
+
- `ComboboxChip` shows its remove button by default (`showRemove`). Colour it with `color` + `tone`, or `customColor` for an arbitrary hex (`legacyColor` is deprecated).
|
|
232
|
+
- Groups of options: use the grouped item shape (Mistake 4) or `DataCombobox` `getGroupKey`.
|
|
233
|
+
|
|
184
234
|
### 5c. Async / paginated — prefer `DataCombobox`
|
|
185
235
|
|
|
186
|
-
For search-as-you-type, paginated (infinite-scroll), or loading-state options, use the batteries-included **`DataCombobox`** instead of hand-rolling the compound parts. It is the combobox analogue of `DataTable` and mirrors its API (`selectionMode` / `selectedKeys` / `loadingState` / `onFetchMore`).
|
|
236
|
+
For search-as-you-type, paginated (infinite-scroll), or loading-state options, use the batteries-included **`DataCombobox`** instead of hand-rolling the compound parts. It is the combobox analogue of `DataTable` and mirrors its API (`selectionMode` / `selectedKeys` / `loadingState` / `onFetchMore`). It is also the closest 1:1 port of Tractor's `selectedKeys`/`onSelectionChange`: keys are **strings** (`getItemValue` returns `string`), so stringify numeric ids, and selection is a `Set<string>`, not `K[]`.
|
|
187
237
|
|
|
188
238
|
```tsx
|
|
189
239
|
import { DataCombobox } from '@aircall/ds';
|
|
190
240
|
|
|
241
|
+
const [selected, setSelected] = React.useState<Set<string>>(new Set());
|
|
242
|
+
|
|
191
243
|
<DataCombobox
|
|
192
244
|
items={results} // the current page you fetched
|
|
193
245
|
getItemValue={r => r.id}
|
|
@@ -200,23 +252,28 @@ import { DataCombobox } from '@aircall/ds';
|
|
|
200
252
|
onFetchMore={fetchNextPage}
|
|
201
253
|
hasMore={hasMore}
|
|
202
254
|
emptyState="No matches."
|
|
255
|
+
aria-label="Contacts"
|
|
203
256
|
/>;
|
|
204
257
|
```
|
|
205
258
|
|
|
206
259
|
- **`loadingState`**: `'loading'` (skeleton rows on first open), `'filtering'` (current results stay under a dimmed spinner overlay while re-querying), `'loadingMore'` (spinner row at the list bottom while paginating). The `'filtering'` overlay dims the **current rows** — keep the previous `items` during the re-query if you want that context (a `keepPreviousData`/`placeholderData` fetch does this for free). With no rows to dim, the spinner shows in a stable min-height box and the "No results" text is hidden until the query settles. The list stays mounted throughout (only initial `'loading'` shows skeletons), so the search input keeps focus.
|
|
207
|
-
- **`onSearch('')`** — called whenever the query
|
|
260
|
+
- **`onSearch('')`** — called whenever the query **ends**: the input's clear (x) button, Base UI's automatic clear after a pick in multi/overlay layout, and every close of the popup (dismissals included) while a query is active. **Treat `''` as "no query": return the initial, unfiltered list**, not `[]` — returning `[]` blanks the list and strands the user on the last search.
|
|
208
261
|
- **`onFetchMore` + `hasMore`** drive infinite scroll (an IntersectionObserver sentinel at the list bottom). While paginating, the built-in **client filter is disabled** (it only sees loaded pages and would hide the sentinel, wedging scroll) — so a **searchable paginated list must use `onSearch`** (server-side); don't rely on typeahead.
|
|
262
|
+
- **`virtualizeRows`** (`boolean | 'auto'`, default `'auto'`) mounts only the visible rows. It turns on by itself once the list declares `onFetchMore` or reaches `COMBOBOX_AUTO_VIRTUALIZE_THRESHOLD` (100) rows, latches on, and is ignored for a grouped list. Pass `estimateRowHeight` (default 36) for rows taller than one line. Pass `false` only to keep every row in the DOM, e.g. in a test.
|
|
263
|
+
- **`searchable`** (`boolean | 'auto'`, default `true`). `false` drops the search: with `trigger` the overlay shows only the list (a short "Status" pick-list); without it the inline single field becomes read-only. `'auto'` searches once the list reaches `COMBOBOX_AUTO_SEARCH_THRESHOLD` (15) rows or whenever `onSearch` is set.
|
|
209
264
|
- **`selectedItems`** seeds labels for a saved value not yet in `items` (edit forms) — otherwise a selected key with no loaded item can't render its label/chip.
|
|
210
|
-
- **`renderItem`** renders rich rows (avatar/flag + title + description) — compose the `Item` primitives at `size="xs"`.
|
|
265
|
+
- **`renderItem`** renders rich rows (avatar/flag + title + description) — compose the `Item` primitives at `size="xs"` with `className="p-0"`.
|
|
211
266
|
- **`renderChip`** (multiple mode) customises the whole selected chip — return a `ComboboxChip` so you can set its `color`/`tone`, e.g. `item => <ComboboxChip color="blue" tone="light">{item.label}</ComboboxChip>`.
|
|
212
|
-
- **`getGroupKey`** (+ optional `getGroupLabel`) groups the flat `items` into labelled sections (first-seen order); selection, keyboard nav, and the async states all work across groups.
|
|
213
|
-
- **`trigger`** swaps the inline field for a custom trigger button and moves search into the overlay (the "Created by" table-filter pattern).
|
|
267
|
+
- **`getGroupKey`** (+ optional `getGroupLabel`) groups the flat `items` into labelled sections (first-seen order); selection, keyboard nav, and the async states all work across groups.
|
|
268
|
+
- **`trigger`** swaps the inline field for a custom trigger button and moves search into the overlay (the "Created by" table-filter pattern). `anchor` lines the popup up with a wider control than the trigger.
|
|
214
269
|
- **`contentClassName`** sets the dropdown width — default `min-w-50` (200px); use `min-w-0` to hug the anchor or `min-w-80` (320px) for a wider menu.
|
|
215
|
-
- **`
|
|
270
|
+
- **`aria-label`** names the field. The field is `role="combobox"` and takes its name only from `aria-label`/`aria-labelledby`, never from a nearby label, so pass it whenever the label is plain text beside the control.
|
|
271
|
+
- **`open` + `onOpenChange(open, details)`**: for a filter that should apply only once the user is **done** (not on every checkbox toggle), keep the live selection in `onSelectionChange` and commit it in `onOpenChange` on the `false` edge (fires exactly once — prefer over blur). `details.reason === 'escape-key'` means discard.
|
|
272
|
+
- **`preserveSearchOnSelect`** (multiple mode) keeps the typed query after a pick so the user can keep narrowing; closing still clears it. `showClear` (default `true`) is the single-select clear button; `disabledKeys` greys rows out.
|
|
216
273
|
|
|
217
274
|
### 5d. Async with full markup control (compound)
|
|
218
275
|
|
|
219
|
-
Only drop to the compound parts when you need markup `DataCombobox` doesn't expose.
|
|
276
|
+
Only drop to the compound parts when you need markup `DataCombobox` doesn't expose. Render only the results you fetched and turn the built-in filter off with `filter={null}`, otherwise Base UI filters the server's answer a second time.
|
|
220
277
|
|
|
221
278
|
```tsx
|
|
222
279
|
import {
|
|
@@ -228,28 +285,33 @@ import {
|
|
|
228
285
|
ComboboxList,
|
|
229
286
|
} from '@aircall/ds';
|
|
230
287
|
|
|
231
|
-
|
|
288
|
+
type Contact = { id: string; name: string };
|
|
289
|
+
|
|
290
|
+
function ContactPicker({ onPick }: { onPick: (contact: Contact | null) => void }) {
|
|
232
291
|
const [query, setQuery] = React.useState('');
|
|
233
|
-
const { data: results, loading } = useSearch(query);
|
|
292
|
+
const { data: results = [], loading } = useSearch(query);
|
|
234
293
|
|
|
235
294
|
return (
|
|
236
|
-
<Combobox
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
295
|
+
<Combobox
|
|
296
|
+
items={results}
|
|
297
|
+
filter={null}
|
|
298
|
+
itemToStringLabel={(c: Contact) => c.name}
|
|
299
|
+
isItemEqualToValue={(a: Contact, b: Contact) => a.id === b.id}
|
|
300
|
+
// Base UI also reports the picked label here (reason 'item-press'); don't search for it
|
|
301
|
+
onInputValueChange={(value, details) => {
|
|
302
|
+
if (details.reason !== 'item-press') setQuery(value);
|
|
303
|
+
}}
|
|
304
|
+
onValueChange={onPick}
|
|
305
|
+
>
|
|
306
|
+
<ComboboxInput placeholder="Search contacts" />
|
|
242
307
|
<ComboboxContent>
|
|
308
|
+
<ComboboxEmpty>{loading ? 'Searching…' : 'No matches.'}</ComboboxEmpty>
|
|
243
309
|
<ComboboxList>
|
|
244
|
-
{
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
)}
|
|
248
|
-
{results.map(r => (
|
|
249
|
-
<ComboboxItem key={r.id} value={r.id}>
|
|
250
|
-
{r.name}
|
|
310
|
+
{(c: Contact) => (
|
|
311
|
+
<ComboboxItem key={c.id} value={c}>
|
|
312
|
+
{c.name}
|
|
251
313
|
</ComboboxItem>
|
|
252
|
-
)
|
|
314
|
+
)}
|
|
253
315
|
</ComboboxList>
|
|
254
316
|
</ComboboxContent>
|
|
255
317
|
</Combobox>
|
|
@@ -268,16 +330,20 @@ function ContactPicker({ onPick }: { onPick: (id: string) => void }) {
|
|
|
268
330
|
<ComboboxItem value="a">Alpha</ComboboxItem>
|
|
269
331
|
</ComboboxContent>
|
|
270
332
|
|
|
271
|
-
// Correct
|
|
333
|
+
// Correct — items go through ComboboxList's render function; ComboboxEmpty sits beside the list
|
|
272
334
|
<ComboboxContent>
|
|
335
|
+
<ComboboxEmpty>No results.</ComboboxEmpty>
|
|
273
336
|
<ComboboxList>
|
|
274
|
-
|
|
275
|
-
|
|
337
|
+
{(item: Option) => (
|
|
338
|
+
<ComboboxItem key={item.value} value={item}>
|
|
339
|
+
{item.label}
|
|
340
|
+
</ComboboxItem>
|
|
341
|
+
)}
|
|
276
342
|
</ComboboxList>
|
|
277
343
|
</ComboboxContent>
|
|
278
344
|
```
|
|
279
345
|
|
|
280
|
-
`ComboboxContent` is the popover shell (portal + positioner + popup). The scrollable
|
|
346
|
+
`ComboboxContent` is the popover shell (portal + positioner + popup). The scrollable list (`overflow-y-auto`, max height, padding) and the render function that maps `items` live in `ComboboxList`. `ComboboxEmpty` is styled to show only when the popup is empty (`group-data-empty/combobox-content`); the stories put it in `ComboboxContent` next to the list.
|
|
281
347
|
Source: `packages/ds/src/components/combobox.tsx`
|
|
282
348
|
|
|
283
349
|
---
|
|
@@ -285,79 +351,66 @@ Source: `packages/ds/src/components/combobox.tsx`
|
|
|
285
351
|
### Mistake 2 — Forgetting `useComboboxAnchor` / not passing `anchor` for multi-select chips
|
|
286
352
|
|
|
287
353
|
```tsx
|
|
288
|
-
// Wrong —
|
|
289
|
-
<Combobox multiple value={selected} onValueChange={setSelected}>
|
|
354
|
+
// Wrong — the popup anchors to the small <input> inside the chips field, not to the field
|
|
355
|
+
<Combobox multiple items={options} value={selected} onValueChange={setSelected}>
|
|
290
356
|
<ComboboxChips>
|
|
291
|
-
|
|
292
|
-
|
|
357
|
+
<ComboboxValue>
|
|
358
|
+
{(values: Option[]) => (
|
|
359
|
+
<>
|
|
360
|
+
{values.map(v => <ComboboxChip key={v.value}>{v.label}</ComboboxChip>)}
|
|
361
|
+
<ComboboxChipsInput placeholder="Add a tag" />
|
|
362
|
+
</>
|
|
363
|
+
)}
|
|
364
|
+
</ComboboxValue>
|
|
293
365
|
</ComboboxChips>
|
|
294
|
-
<ComboboxContent>
|
|
295
|
-
<ComboboxList>
|
|
296
|
-
{items.map(i => <ComboboxItem key={i.value} value={i.value}>{i.label}</ComboboxItem>)}
|
|
297
|
-
</ComboboxList>
|
|
298
|
-
</ComboboxContent>
|
|
366
|
+
<ComboboxContent>…</ComboboxContent>
|
|
299
367
|
</Combobox>
|
|
300
368
|
|
|
301
369
|
// Correct
|
|
302
|
-
const
|
|
370
|
+
const anchor = useComboboxAnchor();
|
|
303
371
|
|
|
304
|
-
<Combobox multiple value={selected} onValueChange={setSelected}>
|
|
305
|
-
<ComboboxChips ref={
|
|
306
|
-
|
|
307
|
-
<ComboboxChipsInput placeholder="Add a tag" />
|
|
308
|
-
</ComboboxChips>
|
|
309
|
-
<ComboboxContent anchor={anchorRef}>
|
|
310
|
-
<ComboboxList>
|
|
311
|
-
{items.map(i => <ComboboxItem key={i.value} value={i.value}>{i.label}</ComboboxItem>)}
|
|
312
|
-
</ComboboxList>
|
|
313
|
-
</ComboboxContent>
|
|
372
|
+
<Combobox multiple items={options} value={selected} onValueChange={setSelected}>
|
|
373
|
+
<ComboboxChips ref={anchor}>…</ComboboxChips>
|
|
374
|
+
<ComboboxContent anchor={anchor}>…</ComboboxContent>
|
|
314
375
|
</Combobox>
|
|
315
376
|
```
|
|
316
377
|
|
|
317
|
-
|
|
378
|
+
Base UI positions the popup against the input group, or failing that the input element. `ComboboxChips` is neither, so without `anchor` the popup lines up with the narrow chip input and is misaligned with, and narrower than, the field. `useComboboxAnchor()` returns a stable `ref` that must be attached to `ComboboxChips` and forwarded to `ComboboxContent`. The popup's width follows its anchor's width, so a chip-input anchor would give a very narrow list.
|
|
318
379
|
Source: `packages/ds/src/components/combobox.tsx`
|
|
319
380
|
|
|
320
381
|
---
|
|
321
382
|
|
|
322
|
-
### Mistake 3 —
|
|
383
|
+
### Mistake 3 — Rendering static `ComboboxItem` children without `items` on the root
|
|
323
384
|
|
|
324
385
|
```tsx
|
|
325
|
-
// Wrong —
|
|
326
|
-
const [query, setQuery] = React.useState('');
|
|
327
|
-
const visible = countries.filter(c =>
|
|
328
|
-
c.name.toLowerCase().includes(query.toLowerCase())
|
|
329
|
-
);
|
|
330
|
-
|
|
386
|
+
// Wrong — no `items`: typing filters nothing, and ComboboxEmpty is shown permanently
|
|
331
387
|
<Combobox value={country} onValueChange={setCountry}>
|
|
332
|
-
<ComboboxInput
|
|
333
|
-
placeholder="Search countries"
|
|
334
|
-
value={query}
|
|
335
|
-
onChange={e => setQuery(e.target.value)}
|
|
336
|
-
/>
|
|
388
|
+
<ComboboxInput placeholder="Search countries" />
|
|
337
389
|
<ComboboxContent>
|
|
390
|
+
<ComboboxEmpty>No results.</ComboboxEmpty>
|
|
338
391
|
<ComboboxList>
|
|
339
|
-
{
|
|
340
|
-
<ComboboxItem key={c.
|
|
392
|
+
{countries.map(c => (
|
|
393
|
+
<ComboboxItem key={c.value} value={c}>{c.label}</ComboboxItem>
|
|
341
394
|
))}
|
|
342
395
|
</ComboboxList>
|
|
343
396
|
</ComboboxContent>
|
|
344
397
|
</Combobox>
|
|
345
398
|
|
|
346
|
-
// Correct — render
|
|
347
|
-
<Combobox value={country} onValueChange={setCountry}>
|
|
348
|
-
<ComboboxInput placeholder="Search countries"
|
|
399
|
+
// Correct — pass `items`; render through the ComboboxList function
|
|
400
|
+
<Combobox items={countries} value={country} onValueChange={setCountry}>
|
|
401
|
+
<ComboboxInput placeholder="Search countries" />
|
|
349
402
|
<ComboboxContent>
|
|
403
|
+
<ComboboxEmpty>No results.</ComboboxEmpty>
|
|
350
404
|
<ComboboxList>
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
))}
|
|
405
|
+
{(c: Country) => (
|
|
406
|
+
<ComboboxItem key={c.value} value={c}>{c.label}</ComboboxItem>
|
|
407
|
+
)}
|
|
355
408
|
</ComboboxList>
|
|
356
409
|
</ComboboxContent>
|
|
357
410
|
</Combobox>
|
|
358
411
|
```
|
|
359
412
|
|
|
360
|
-
|
|
413
|
+
Base UI derives the filtered list from the root's `items`. Without it that list is always empty: the typed query hides nothing, and `ComboboxEmpty` (which renders when the filtered list is empty) never goes away. Do not write a manual `filter()` loop either: for a static list pass all `items` and let Base UI filter; for a server-driven list pass the fetched results with `filter={null}` (§5d) or use `DataCombobox` with `onSearch`.
|
|
361
414
|
Source: `packages/ds/src/components/combobox.tsx`
|
|
362
415
|
|
|
363
416
|
---
|
|
@@ -365,7 +418,7 @@ Source: `packages/ds/src/components/combobox.tsx`
|
|
|
365
418
|
### Mistake 4 — Placing `ComboboxLabel` directly in `ComboboxList` without a `ComboboxGroup`
|
|
366
419
|
|
|
367
420
|
```tsx
|
|
368
|
-
// Wrong
|
|
421
|
+
// Wrong — throws "ComboboxGroupContext is missing"
|
|
369
422
|
<ComboboxList>
|
|
370
423
|
<ComboboxLabel>Suggestions</ComboboxLabel>
|
|
371
424
|
<ComboboxItem value="a">Alpha</ComboboxItem>
|
|
@@ -380,5 +433,36 @@ Source: `packages/ds/src/components/combobox.tsx`
|
|
|
380
433
|
</ComboboxList>
|
|
381
434
|
```
|
|
382
435
|
|
|
383
|
-
`ComboboxLabel` maps to Base UI's `
|
|
384
|
-
|
|
436
|
+
`ComboboxLabel` maps to Base UI's `Combobox.GroupLabel`, which reads its group's context and throws outside a `ComboboxGroup`. That static form only suits a short, unfiltered list (leave out `ComboboxEmpty`: with no `items` on the root it never hides, see Mistake 3). For a **filterable** grouped list, give the root grouped items (`[{ value: 'Suggestions', items: [...] }]`) and render each group with its own collection, or use `DataCombobox` with `getGroupKey`:
|
|
437
|
+
|
|
438
|
+
```tsx
|
|
439
|
+
<ComboboxList>
|
|
440
|
+
{(group: { value: string; items: Option[] }) => (
|
|
441
|
+
<ComboboxGroup key={group.value} items={group.items}>
|
|
442
|
+
<ComboboxLabel>{group.value}</ComboboxLabel>
|
|
443
|
+
<ComboboxCollection>
|
|
444
|
+
{(item: Option) => <ComboboxItem key={item.value} value={item}>{item.label}</ComboboxItem>}
|
|
445
|
+
</ComboboxCollection>
|
|
446
|
+
</ComboboxGroup>
|
|
447
|
+
)}
|
|
448
|
+
</ComboboxList>
|
|
449
|
+
```
|
|
450
|
+
Source: `packages/ds/src/components/combobox.tsx`, `packages/ds/src/components/combobox-rows.tsx`
|
|
451
|
+
|
|
452
|
+
---
|
|
453
|
+
|
|
454
|
+
### Mistake 5 — Mixing the two tiers' selection props
|
|
455
|
+
|
|
456
|
+
```tsx
|
|
457
|
+
// Wrong — DataCombobox has no value/onValueChange; Combobox has no selectedKeys/onSelectionChange
|
|
458
|
+
<DataCombobox items={users} value={user} onValueChange={setUser} … />
|
|
459
|
+
<Combobox items={users} selectedKeys={keys} onSelectionChange={setKeys}>…</Combobox>
|
|
460
|
+
|
|
461
|
+
// Correct
|
|
462
|
+
<DataCombobox items={users} getItemValue={u => u.id} getItemLabel={u => u.name}
|
|
463
|
+
selectedKeys={keys} onSelectionChange={setKeys} /> // keys: Set<string>
|
|
464
|
+
<Combobox items={users} value={user} onValueChange={setUser}>…</Combobox> // user: User | null
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
`DataCombobox` owns the item objects and exposes selection as a `Set<string>` of keys (`getItemValue`), like `DataTable`. The primitives are Base UI's `Combobox` and carry the selected item (or items) themselves.
|
|
468
|
+
Source: `packages/ds/src/components/data-combobox.tsx`
|