@magicx-eng/ai-autocomplete-react 0.47.1 → 0.48.1

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/REFERENCE.md ADDED
@@ -0,0 +1,594 @@
1
+ # @magicx-eng/ai-autocomplete-react reference
2
+
3
+ Longer guides that do not fit in the [README](https://unpkg.com/@magicx-eng/ai-autocomplete-react/README.md) on the npm page. This file ships in the package, at `node_modules/@magicx-eng/ai-autocomplete-react/REFERENCE.md`.
4
+
5
+ - [Product strip](#product-strip)
6
+ - [Datepicker](#datepicker)
7
+ - [Time picker](#time-picker)
8
+ - [Multiple selections](#multiple-selections)
9
+ - [Location search](#location-search)
10
+ - [CSS variables](#css-variables)
11
+
12
+ ## Product strip
13
+
14
+ The dropdown renders a horizontal row of product cards below the options grid
15
+ whenever it has products to show. By default those are the items the
16
+ `/suggest` response itself reports as matching the query. No configuration,
17
+ no extra request: the cards land in the same state update as the suggestions,
18
+ so what the strip shows and what the pills offer always describe the same
19
+ narrowing.
20
+
21
+ ```tsx
22
+ <AIAutocomplete
23
+ onSubmit={handleSubmit}
24
+ // Selection emits an event. The SDK never navigates.
25
+ onProductSelect={(product) => product.url && router.push(product.url)}
26
+ />
27
+ ```
28
+
29
+ Each server item becomes a `Product` with `id` (the item's stable id), `title`,
30
+ `price` (the item's lowest price, verbatim as the catalog spells it; the
31
+ currency is yours to add), `compareAtPrice` (the price before a markdown, on a
32
+ discounted item only, struck through beside the price), `vendor`, `imageUrl`, and a `url`: the item's own
33
+ `item_url` when the uploaded catalog named one (absolute or root-relative;
34
+ anything else is ignored), else a **relative** `/products/{handle}` (the right
35
+ link for a Shopify widget running on the storefront itself), opened on the
36
+ variant the query chose (`?variant=…`, e.g. the blue one for "blue shoes") when
37
+ there is one, whose price and image the card then shows. `available` is carried
38
+ over when the server reports it. An item with
39
+ neither gets no `url`: its card is still activatable and still emits
40
+ `onProductSelect`, it just has nothing for cmd-click to open. `productFromMatchedItem` / `productsFromCustomFields` are
41
+ exported for a hand-rolled strip that wants the same mapping.
42
+
43
+ Pass `showProducts={false}` to render no strip at all. The catalog report
44
+ (below) stays readable either way.
45
+
46
+ `productsLayout="list"` stacks the same cards as full-width rows (thumbnail
47
+ on the left, title, vendor and price on the right) for results that read as
48
+ a list (courses, listings, documents) rather than products on a shelf. The
49
+ column scrolls vertically inside `--aia-product-list-max-height` (320px by
50
+ default); `--aia-product-list-media-size` (44px) sizes the thumbnail and
51
+ `--aia-product-list-gap` (2px) the space between rows. `"row"`, the default,
52
+ is the horizontal strip. Changing the prop re-lays the strip out at once, and
53
+ `<AIAutocompleteDropdown>` takes the same prop in Tier 2.
54
+
55
+ **Product image fallback.** A product's image takes priority when its
56
+ `imageUrl` loads successfully. A missing or blank URL, or an image load error,
57
+ uses `productImageFallback`: `"image"` (the default) shows the existing
58
+ placeholder pictogram; `"initial"` shows the first character of the trimmed,
59
+ uppercased title. This is a Unicode grapheme (so a combined character or emoji
60
+ stays together), with a Unicode code point fallback in older browsers. An
61
+ empty or whitespace-only title shows `?`. The fallback works in both row and
62
+ list layouts. Initial tiles are decorative (`aria-hidden="true"`); the card's
63
+ visible title supplies its text.
64
+
65
+ **Sold out.** A product with `available: false` shows a "Sold out" badge over
66
+ the top-left of its image (in the list layout, a smaller banner across the
67
+ bottom of the thumbnail) and its image is desaturated; the card stays
68
+ selectable and keeps its link. Absent or `true` shows no
69
+ badge, so leave `available` out when you don't know. The badge is part of the
70
+ card's text, so screen readers announce it. Theme it with
71
+ `--aia-product-badge-bg`, `--aia-product-badge-color`,
72
+ `--aia-product-badge-font-size` and `--aia-product-badge-inset`, and the list
73
+ banner with `--aia-product-badge-list-bg`, `--aia-product-badge-list-color` and
74
+ `--aia-product-badge-list-font-size`.
75
+
76
+ Pass `productImageFallback="initial"` to `<AIAutocomplete>` or
77
+ `<AIAutocompleteDropdown>`. The hook also accepts the option and carries it
78
+ through `dropdownProps`:
79
+
80
+ ```tsx
81
+ // Tier 1
82
+ <AIAutocomplete onSubmit={handleSubmit} productImageFallback="initial" />;
83
+
84
+ // Tier 2
85
+ function ProductSearch() {
86
+ const { inputProps, dropdownProps } = useAIAutocomplete({
87
+ productImageFallback: "initial",
88
+ });
89
+ return (
90
+ <>
91
+ <textarea {...inputProps} />
92
+ <AIAutocompleteDropdown {...dropdownProps} mode="auto" />
93
+ </>
94
+ );
95
+ }
96
+ ```
97
+
98
+ Style the initial tile itself with `[data-aia-product-initial]`. For
99
+ example, wrap the widget in an element with `id="catalog-search"` and add this
100
+ rule to your stylesheet. The existing `--aia-product-media-bg` variable sets
101
+ the background; `color`, `font-size` and `border-radius` style the initial
102
+ without additional SDK options.
103
+
104
+ ```css
105
+ #catalog-search [data-aia-product-initial] {
106
+ --aia-product-media-bg: #eef2ff;
107
+ color: #4338ca;
108
+ font-size: 22px;
109
+ border-radius: 12px;
110
+ }
111
+ ```
112
+
113
+ ### The catalog report (`customFields`)
114
+
115
+ Every response that read the catalog also says what it did with the query. The
116
+ hook returns it as `customFields`, and it rides on `AutocompleteResult` as
117
+ `custom_fields`, so `onResult` on either tier carries it too:
118
+
119
+ ```tsx
120
+ const { customFields } = useAIAutocomplete({ ... });
121
+
122
+ // Or, on Tier 1:
123
+ <AIAutocomplete onResult={(result) => setReport(result.custom_fields)} />
124
+
125
+ {report && <p>{report.items.total} results</p>}
126
+ {report?.dropped_filters.length > 0 && (
127
+ // e.g. { parameter: "Color", value: "Chartreuse", op: "eq" }: the shopper asked
128
+ // for a colour no item carries, so the results ignore it. Say so.
129
+ <p>No match for {report.dropped_filters.map((f) => f.value).join(", ")}</p>
130
+ )}
131
+ ```
132
+
133
+ - `applied_filters` / `dropped_filters`: the constraints the server read out
134
+ of the query as `{ parameter, value, op }` (`op` is one of `eq`, `ne`, `lt`,
135
+ `lte`, `gt`, `gte`), split into the ones the catalog answered and the ones it
136
+ could not (a parameter it does not have, a bound that is not a number, a
137
+ value no item carries). The items answer the applied set, so the dropped
138
+ list is what tells "87 black t-shirts" from "no black item, so here are
139
+ t-shirts". Both are always arrays.
140
+ - `items.total`: how many items the applied filters left standing. It also
141
+ moves with the query's own words, so it drops as a typed word starts
142
+ matching a title. `items.matched` is the list the strip renders, capped by
143
+ the server; it is empty (with a non-zero `total`) when nothing narrowed the
144
+ catalog, where listing arbitrary items as matches would mislead.
145
+ - `null` (no `custom_fields` key on the result) means the response carried no
146
+ report: no catalog was read for it (a product with no catalog, the starting
147
+ state, a response with no option-bearing parameter to offer). That is "no
148
+ news", not an empty catalog. The strip clears on such a response rather than
149
+ keeping an older query's items.
150
+
151
+ ### Change product cards before display
152
+
153
+ - `mapProducts(products, items)` synchronously returns the cards to show.
154
+ - The SDK calls it once per response with its default cards and their matched items in the same order.
155
+ - The returned array becomes the product state and the displayed strip.
156
+ - A thrown error or a non-array result keeps the default cards. A thrown error warns once per instance.
157
+ - `refreshProducts()` maps the current items again without a request. Call it when your own data arrives.
158
+ - Both APIs leave a custom `products` integration unchanged.
159
+
160
+ ```tsx
161
+ const { actions } = useAIAutocomplete({
162
+ mapProducts: (products, items) =>
163
+ products.map((product, index) => ({
164
+ ...product,
165
+ price: shopperPrices[items[index].source_id] ?? "",
166
+ })),
167
+ });
168
+
169
+ // After updating shopperPrices:
170
+ actions.refreshProducts();
171
+ ```
172
+
173
+ - `<AIAutocomplete mapProducts={mapProducts} />` accepts the same callback.
174
+ - Call `ref.current?.refreshProducts()` through the component's imperative handle.
175
+ - Inline callbacks do not trigger repeated mapping on each render. A refresh uses the latest callback.
176
+
177
+ ### Your own product search (`products`)
178
+
179
+ To source the cards from your own search instead (a platform with its own
180
+ endpoint and response shape), pass `products`. The SDK owns the UI; you own
181
+ only the fetching and the mapping. The server's items are then not rendered
182
+ (they stay readable on `customFields`).
183
+
184
+ ```tsx
185
+ import { AIAutocomplete, type Product } from "@magicx-eng/ai-autocomplete-react";
186
+
187
+ const products = {
188
+ // You own the request entirely: auth headers, GraphQL body, locale
189
+ // prefixes. Honour the signal: the SDK aborts it as soon as a newer query
190
+ // supersedes this one.
191
+ fetch: (query: string, signal: AbortSignal) =>
192
+ fetch(`/api/products?q=${encodeURIComponent(query)}`, { signal }).then((r) => r.json()),
193
+
194
+ // Pure mapping, kept out of `fetch` so you can unit-test it without a
195
+ // network.
196
+ transform: (raw: unknown): Product[] =>
197
+ (raw as ApiResponse).items.map((item) => ({
198
+ id: item.id,
199
+ title: item.title,
200
+ url: item.url,
201
+ imageUrl: item.image?.src ?? null, // null uses the configured productImageFallback
202
+ price: formatMoney(item.price), // you know the currency
203
+ vendor: item.brand,
204
+ })),
205
+
206
+ limit: 8, // applied by the SDK, after transform
207
+ };
208
+
209
+ <AIAutocomplete
210
+ onSubmit={handleSubmit}
211
+ products={products}
212
+ onProductSelect={(product) => product.url && router.push(product.url)}
213
+ />;
214
+ ```
215
+
216
+ `Product` is exactly seven fields; only `id` and `title` are required:
217
+
218
+ ```ts
219
+ type Product = {
220
+ id: string;
221
+ title: string;
222
+ url?: string; // absent = a card with no link (still activatable)
223
+ imageUrl?: string | null;
224
+ price?: string;
225
+ compareAtPrice?: string; // the price before a markdown; struck through beside price
226
+ vendor?: string;
227
+ available?: boolean; // false shows a "Sold out" badge
228
+ };
229
+ ```
230
+
231
+ **What the SDK guarantees**
232
+
233
+ - **One fetch cadence.** The product search rides the same debounce, the same
234
+ `AbortController` and the same version guard as `/suggest`, so there is no
235
+ second timer to drift out of step.
236
+ - **Empty queries never reach you.** On mount and after `reset()` the strip
237
+ clears.
238
+ - **Out-of-order responses are dropped.** A slow response for an older query is
239
+ never rendered over a newer one.
240
+ - **Failure is silent.** A rejected `fetch` or a throwing `transform` clears the
241
+ strip, logs once, and leaves the suggestions half untouched: no `error`
242
+ state, no `onError`, no effect on `isLoading`.
243
+ - **The two halves are independent.** The panel opens if *either* has content,
244
+ so products keep it open when option filtering empties the option list.
245
+ `dropdownTrigger` (`manual` / `hidden`) still gates the panel as before.
246
+ - **Inline configs are safe.** `products={{ fetch, transform }}` written inline
247
+ re-creates the object on every render; the hook forwards through a stable
248
+ proxy, so only setting or removing the config reaches the core. Two
249
+ deliberate consequences: swapping one live config for another leaves the
250
+ previous integration's cards up until the next request replaces them
251
+ (remove `products` and set it again to clear immediately), and setting a
252
+ config mid-session shows nothing until the next `/suggest` request fires:
253
+ the product search rides that one scheduler, and configuring it doesn't
254
+ itself change the query. Removing the config restores the server's items at
255
+ once.
256
+
257
+ **Add to cart.** Pass `onProductAddToCart` and every card that isn't sold out
258
+ (`available: false`) shows a round cart button over the bottom-right corner of
259
+ its image (in the list layout, at the right end of the row). Leave it unset and
260
+ no card has one. The SDK never touches a cart: pressing the button calls your
261
+ handler with the card's `Product`, and does not fire `onProductSelect`,
262
+ navigate or close the panel.
263
+
264
+ ```tsx
265
+ <AIAutocomplete
266
+ onSubmit={handleSubmit}
267
+ onProductAddToCart={(product) => cart.add(product.id)}
268
+ />
269
+ ```
270
+
271
+ Return a promise to have the button show progress. While it is pending the
272
+ button carries `data-aia-cart-state="adding"` (and `aria-busy="true"`), spins
273
+ and ignores further presses; once it resolves the cart turns into a check
274
+ (`data-aia-cart-state="added"`) and stays one until the card's product changes
275
+ (a price-only change keeps it). Pressing it again adds another unit, back
276
+ through "adding" to "added". A rejection puts the button back at rest — show your own error. A handler that returns nothing goes
277
+ straight to "added". The button is labelled "Add to cart: {title}" in the
278
+ widget language, reachable by Tab and pressed with Enter or Space. Theme it
279
+ with `--aia-product-cart-size` (28px), `--aia-product-cart-bg` and
280
+ `--aia-product-cart-color`; its focus ring uses `--aia-product-focus-ring`.
281
+ The button is a `[data-aia-product-cart]` element, and a card that has one
282
+ carries `data-aia-product-has-cart`.
283
+
284
+ **Selection and links.** Cards are real `<a href>` elements, so cmd/ctrl-click,
285
+ middle-click and "copy link address" behave natively. A plain left click is
286
+ intercepted (`preventDefault`) and emits `onProductSelect` instead.
287
+
288
+ `product.url` is used verbatim: the SDK trusts your `transform` output and
289
+ does not sanitise it, so validate the URL there if the platform response isn't
290
+ fully under your control. (Angular additionally runs its own `href`
291
+ sanitiser, so unrecognised schemes like `myapp://…` are rewritten to
292
+ `unsafe:…` in that package only.)
293
+
294
+ **Accessibility.** The strip is a `role="group"` labelled "Best match"; each card
295
+ is a `role="option"` in the tab order, activated with Enter or Space, with a
296
+ visible focus ring. Tabbing into the strip does not close the panel. The row
297
+ scrolls horizontally by trackpad, wheel, touch and keyboard; the page never
298
+ scrolls sideways and the scrollbar chrome is hidden in all engines.
299
+
300
+ Tier 2 gets the same thing: `useAIAutocomplete()` takes `showProducts`,
301
+ `products`, `productImageFallback` and `onProductSelect`, and the strip renders inside
302
+ `<AIAutocompleteDropdown />` via `dropdownProps`. Tier 3 consumers read
303
+ `products` (and `customFields`) from the hook and call
304
+ `selectProduct(product)` from their own cards.
305
+
306
+ ## Datepicker
307
+
308
+ When the next parameter is a date, the dropdown shows a calendar instead of a
309
+ list of options. Which parameters are dates is the server's call: one whose
310
+ `type` is `date` gets a calendar, and one without a date type keeps its option
311
+ list, however date-like its name or options look.
312
+
313
+ Nothing is required to switch it on: a date parameter renders this way
314
+ automatically, and every other parameter is unaffected. Tier 1 and Tier 2
315
+ render the calendar for you; in Tier 3 the same data reaches `dropdownProps` so
316
+ you can render your own (see [Tier 3](README.md#tier-3-headless)).
317
+
318
+ **What the user can do**
319
+
320
+ | Input | Result |
321
+ |---|---|
322
+ | Click a day | Commits that date |
323
+ | <kbd>↓</kbd> | Moves into the calendar, starting on today |
324
+ | <kbd>←</kbd> / <kbd>→</kbd> | Previous / next day, crossing week boundaries |
325
+ | <kbd>↑</kbd> / <kbd>↓</kbd> | Previous / next week. Past either end of the month, focus returns to the input |
326
+ | <kbd>Enter</kbd> | Commits the highlighted day |
327
+ | Month arrows | Page the calendar. Paging never commits anything |
328
+ | <kbd>→</kbd> at the end of the input | Skips the parameter, same as any other pill |
329
+
330
+ **The committed value** is written the way a person would write it, always in
331
+ English regardless of the visitor's locale, so the value you receive has one
332
+ vocabulary everywhere:
333
+
334
+ - a date inside the next week (today included) commits as its weekday name:
335
+ `Tuesday`. Like the sentence it sits in, that name is relative: read later,
336
+ it means the next such day;
337
+ - one further out in the current year as `MONTH DAY`: `March 23`;
338
+ - one in another year as `MONTH DAY YEAR`: `March 23 2027`.
339
+
340
+ It arrives as an ordinary completed parameter: bold in the input,
341
+ and present in `completed_params` on submit like any other answer.
342
+
343
+ **Re-editing** a committed date re-opens the calendar on the month the committed
344
+ text names, with that day marked, so changing an answer takes one click. For a
345
+ weekday name that reading is relative, so once the day it named has gone by,
346
+ re-editing marks the next such day rather than the one originally picked: the
347
+ calendar shows what the sentence says today, which is also what gets submitted.
348
+
349
+ **Reading the value back.** The date arrives as text, so if you need a `Date`
350
+ object, `parseDate` is exported for it:
351
+
352
+ ```ts
353
+ import { parseDate } from "@magicx-eng/ai-autocomplete-react";
354
+
355
+ // Reads all three committed shapes: a weekday name is the one date it can
356
+ // mean in the next seven days, and a yearless month-day is the current year.
357
+ const due = parseDate("March 23"); // Date, or null if the text isn't one of ours
358
+ ```
359
+
360
+ `parseLooseDate` is exported too, for the looser shapes a person types into a
361
+ query: it reads `september 5th`, `5th September`, `Sept 5` and `2026-09-05`,
362
+ and answers `null` for anything ambiguous rather than guessing.
363
+
364
+ **Dates the user writes themselves.** When someone types a date into their query
365
+ ("fly to vegas on september 5th"), the parameter it answers is recognised in
366
+ place and the date becomes tappable. Tapping it opens the calendar on that
367
+ month with the day already marked, so confirming or changing it takes one tap,
368
+ and the picked date replaces their words with the canonical form.
369
+
370
+ The written date is read where it can be: `september 5th`, `5th September`,
371
+ `Sept 5`, `September 5, 2026` and `2026-09-05` all resolve, in any of those
372
+ orders and with or without the year (a date with no year means its next
373
+ occurrence). Two cases deliberately don't pre-select: a numeric date like
374
+ `09/05`, which is September 5th in the US and May 9th elsewhere with nothing to
375
+ say which, and phrases like `next friday`. Those still open the calendar, just
376
+ on the current month with nothing marked, so the user picks rather than being
377
+ shown a guess that might be wrong.
378
+
379
+ **Date ranges.** A parameter whose `type` is `date_range` is answered by the
380
+ same calendar in two clicks: the first sets the start, the second the end, and the pair
381
+ commits as one answer. The days between them band as the user moves across the
382
+ calendar, so the span being chosen is visible before it is committed. Paging the
383
+ month between the two clicks is expected (that is how a span crosses months),
384
+ and <kbd>Esc</kbd> drops the start and lets them begin again. Clicking the end
385
+ before the start is fine; the two are ordered on the way in.
386
+
387
+ It commits as one parameter, written as a span,
388
+ `September 11 - October 13`, with the year on whichever end needs it, and both
389
+ ends are also recorded on the completed parameter's `metadata` as `YYYY-MM-DD`,
390
+ under the `DATE_RANGE_META_START` / `DATE_RANGE_META_END` keys this package
391
+ exports (`aiaDateRangeStart` / `aiaDateRangeEnd`), so you never have to parse
392
+ the prose. Re-editing one re-opens the calendar with both ends marked.
393
+
394
+ **Typing** while the calendar is open does not filter it. The text is treated as
395
+ a new query, so suggestions refresh as the user types, which helps when someone
396
+ would rather describe what they want than pick a day.
397
+
398
+ ## Time picker
399
+
400
+ When the next parameter is a time, the dropdown shows a time wheel instead of a
401
+ list of options. As with dates, which parameters are times is the server's call:
402
+ one whose `type` is `time` gets the wheel, and one without it keeps its option
403
+ list, however time-like its options look.
404
+
405
+ Nothing is required to switch it on. The options the server still sends for a
406
+ time parameter are never shown, but they choose where the wheel opens: on the
407
+ middle of the times suggested (`6 PM`, `7 PM`, `8 PM` opens on 7:00 PM), or on
408
+ the next whole hour when there are none.
409
+
410
+ **What the user can do**
411
+
412
+ | Input | Result |
413
+ |---|---|
414
+ | Scroll or tap a wheel | Turns that wheel; the time on the top rows is the time. Commits nothing |
415
+ | <kbd>↓</kbd> / <kbd>↑</kbd> in the input | Moves the time 5 minutes later / earlier |
416
+ | <kbd>Enter</kbd> | Commits the time — once the wheel has been moved. Until then it is only a suggestion, and Enter submits as usual |
417
+ | Done | Commits the time |
418
+ | <kbd>Esc</kbd> | Puts a moved wheel back on its suggested time |
419
+ | <kbd>→</kbd> at the end of the input | Skips the parameter, same as any other pill |
420
+
421
+ **The committed value** is written the way a person would write it, always in
422
+ English: `7:30 PM`, `12:05 AM`. It arrives as an ordinary completed parameter
423
+ (bold in the input, in `completed_params` on submit) with the server's lead-in
424
+ before it when there is one (`at 7:30 PM`). The exact time is also recorded on
425
+ the parameter's `metadata` as 24-hour `HH:MM` under the `TIME_META_KEY` key
426
+ (`aiaTime`), so you never have to parse the prose:
427
+
428
+ ```ts
429
+ import { parseTime, TIME_META_KEY } from "@magicx-eng/ai-autocomplete-react";
430
+
431
+ const time = param.metadata?.[TIME_META_KEY]; // "19:30"
432
+ const minutes = parseTime(param.text); // 1170 — minutes since midnight, or null
433
+ ```
434
+
435
+ **Re-editing** a committed time re-opens the wheel on it.
436
+
437
+ **Typing** while the wheel is open does not filter anything. As with the
438
+ calendar, the text is treated as a new query.
439
+
440
+ ## Multiple selections
441
+
442
+ - A suggestion with `type: { kind: "multi_select" }` shows checkbox options and a Done button.
443
+ - The option list shows three rows and scrolls the rest, on every screen size, so Done is always in view right under it.
444
+ - A click or tap on a row's checkbox (or just beside it) ticks the row and waits for Done. A click or tap anywhere else on the row (its text, or the space after it) answers right away with that option, together with anything already ticked. Space and Enter always tick. In code: `selectOption(option, { commit: true })`.
445
+ - Select rows to toggle values. Typing filters the options and keeps the current picks.
446
+ - Done joins the picks in selection order with the UI language's word for "and".
447
+ - Each value has its own `completed_params` entry. The input shows one chip for the group.
448
+ - Remove the group chip to change the answer. Group chips do not open for editing.
449
+ - Done without picks skips the question. Typing a phrase with no matching options closes the question and keeps that phrase.
450
+ - Space toggles the highlighted row when nothing is typed for the question. Enter commits the picks, or selects the highlighted row when no values are picked.
451
+ - Headless integrations can call `toggleMultiSelectOption(option)` and `commitMultiSelect()`.
452
+ - `multiSelectView.picked` contains the selected option texts. The view is null outside a multi_select question.
453
+
454
+ ## Location search
455
+
456
+ A location parameter is answered one of two ways, depending on whether the
457
+ server sends options for it. As with dates, which parameters are
458
+ locations is the server's call: it marks them `type: { kind: "location" }`.
459
+
460
+ - **With options** (a catalog with a `city` field, say), it is an ordinary
461
+ option list. Nothing changes.
462
+ - **Without options**, the dropdown shows a search field instead. Typing in it
463
+ searches places through the MagicX server, which proxies a location provider,
464
+ and lists what it finds; any city, address or landmark can be picked.
465
+
466
+ Nothing is required to switch it on. The field searches
467
+ `…/locations/autocomplete`, next to your `/suggest` endpoint
468
+ (`/api/suggest` → `/api/locations/autocomplete`). If `apiConfig.endpoint`
469
+ points at a proxy with its own path, set `apiConfig.locationEndpoint` too.
470
+ The SDK calls that route directly; `/suggest` doesn't need to say anything
471
+ about it. If the route answers 404 (a server without it), the field takes
472
+ typed text for the rest of the session. Any other failure (401, 429, a
473
+ timeout) only costs that one search: Enter commits the typed text, and the
474
+ next phrase tries again.
475
+
476
+ **Turning the search off.** Set the `locationSearch={false}` prop (or the hook option) to keep the field but take typed text
477
+ only — nothing the user types is sent for a lookup.
478
+
479
+ **Your own places.** An `optionOverrides` entry for the parameter takes
480
+ priority over the search: the parameter is answered from your list like any
481
+ other option list (a store's branches, say), and the search never runs.
482
+
483
+ **What the user can do**
484
+
485
+ | Input | Result |
486
+ |---|---|
487
+ | The pill coming up while the user is typing | Focus moves into the search field, so the place is typed straight into it |
488
+ | Typing in the field | Searches after a short pause (2 characters or more) |
489
+ | <kbd>↓</kbd> / <kbd>↑</kbd> | Moves through the places found |
490
+ | <kbd>Enter</kbd> or a tap on a place | Commits it. With nothing found, Enter commits the typed text as written. So does Enter pressed before the search answers (within the 250ms pause): nothing is highlighted yet |
491
+ | <kbd>Esc</kbd>, or <kbd>Backspace</kbd> in an empty field | Back to the input, the pill left open |
492
+ | <kbd>Tab</kbd> / <kbd>Shift</kbd>+<kbd>Tab</kbd> | On to the next control / back to the input, as for any field |
493
+
494
+ **The committed value** reads as the place and its region (`Seattle, WA`), with
495
+ the server's lead-in before it when there is one (`in Seattle, WA`). A picked
496
+ place also records the provider's place ID on the parameter's `metadata` under
497
+ `LOCATION_META_KEY` (`aiaPlace`); typed text records none:
498
+
499
+ ```ts
500
+ import { LOCATION_META_KEY } from "@magicx-eng/ai-autocomplete-react";
501
+
502
+ const place = param.metadata?.[LOCATION_META_KEY]; // { id: "ChIJ…" } | undefined
503
+ ```
504
+
505
+ **Re-editing** a committed place re-opens the field on it, selected, so typing
506
+ replaces it.
507
+
508
+ ---
509
+
510
+ ## CSS variables
511
+
512
+ Override on the container (via `className`). The variables are declared with `:where()` (zero specificity), so a value you set on the container always wins.
513
+
514
+ The full input also accepts `--aia-input-radius` and `--aia-written-text-font-weight` on its container or an ancestor. Omit them to retain the default `10px` radius and `300` weight; changing `mode` does not reset these overrides. In dropdown-only integrations, style your own input directly.
515
+
516
+ ```css
517
+ .my-search {
518
+ --aia-input-radius: 0;
519
+ --aia-written-text-font-weight: 500;
520
+ }
521
+ ```
522
+
523
+ | Variable | Light | Dark | Description |
524
+ |---|---|---|---|
525
+ | `--aia-font-family` | `inherit` | `inherit` | Font used by the library. Defaults to `inherit` so the library picks up your page's font automatically. Set this to pin a specific font on the library without changing the surrounding page. |
526
+ | `--aia-pill-bg` | `#bdbdbd` | `#bdbdbd` | Pill background |
527
+ | `--aia-pill-color` | `#000000` | `#ffffff` | Pill text |
528
+ | `--aia-pill-font-size` | `19px` | `19px` | Pill font size |
529
+ | `--aia-option-bg` | `transparent` | `transparent` | Highlighted option background |
530
+ | `--aia-option-color` | `#000000` | `#ffffff` | Option text |
531
+ | `--aia-option-color-selected` | `#000000` | `#ffffff` | Highlighted option text |
532
+ | `--aia-option-font-size` | `19px` | `19px` | Option font size |
533
+ | `--aia-written-text-color` | `#000000` | `#ffffff` | Input text |
534
+ | `--aia-written-text-font-size` | `19px` | `19px` | Input text font size |
535
+ | `--aia-written-text-font-weight` | `300` | `300` | Written text weight in the full input. Completed chips keep their own typography. |
536
+ | `--aia-caret-color` | `--aia-written-text-color` | `--aia-written-text-color` | Editor caret color. Override independently of input text color. |
537
+ | `--aia-submit-bg` | `#000000` | `#ffffff` | Submit button background. Solid + full-opacity at rest, even when the input is empty/disabled. |
538
+ | `--aia-submit-color` | `#ffffff` | `#000000` | Submit button arrow color |
539
+ | `--aia-submit-bg-disabled` | `--aia-submit-bg` | `--aia-submit-bg` | Submit background when disabled (empty input). Defaults to the enabled background so themed colors aren't washed out. Set this for a faded rest state. |
540
+ | `--aia-submit-bg-ready` | `--aia-submit-bg` | `--aia-submit-bg` | Submit background once the request is complete (the button also lifts slightly). Defaults to the enabled background. |
541
+ | `--aia-submit-color-disabled` | `--aia-submit-color` | `--aia-submit-color` | Submit arrow color when disabled. Defaults to the enabled color. |
542
+ | `--aia-border` | `rgba(17, 24, 39, 0.14)` | `#505050` | Input container border color |
543
+ | `--aia-input-radius` | `10px` | `10px` | Full input corner radius. Set `0` for square corners. |
544
+ | `--aia-shadow` | `none` | `none` | Input container elevation (box-shadow). Flat by default; set it to add one |
545
+ | `--aia-dropdown-offset` | `13px` | `13px` | Gap between the input box and the dropdown (the dropdown's margin toward the input). |
546
+ | `--aia-content-inset-left` | `16px` | `16px` | Left inset of the SDK's content: the input wrapper's left padding, and the line the dropdown's content (parameter label, option text, product strip) starts on. Set it when you pad the field to clear a leading icon of your own, so the dropdown's content stays aligned under the typed text. Practical minimum is `10px` (the option text's own inset); both surfaces floor it there. |
547
+ | `--aia-footer-gap` | `12px` | `12px` | Breathing room above the dropdown footer (badge / keyboard hints), additive to the dropdown's 8px section gap. |
548
+ | `--aia-footer-chip-bg` | `--aia-surface` at 65% | `--aia-surface` at 65% | Fill behind the footer's keyboard hint and AI-Autocomplete badge. The option list scrolls under the footer, so this keeps both legible over the row passing behind them. `transparent` on the glass surface. |
549
+ | `--aia-dropdown-bg` | — | — | Optional bg color the dropdown's "glass" rim shadow tints toward. Set this to the page background behind the dropdown so the bottom-corner glow blends seamlessly. |
550
+ | `--aia-scrollbar-thumb` | `rgba(0, 0, 0, 0.3)` | `rgba(0, 0, 0, 0.3)` | No longer used: the option list hides its scrollbar in every browser. Kept so existing overrides don't break. |
551
+ | `--aia-streak-rgb` | `99, 102, 241` | `255, 255, 255` | Comma-separated RGB triplet tinting the datepicker's pressed cell, and its selected cell when `--aia-date-selected-bg` is unset. The today ring uses `--aia-date-today-ring`, not this. |
552
+ | `--aia-product-card-width` | `116px` | `116px` | Width of a product card in the strip. The media tile is square, so this also sets its height. |
553
+ | `--aia-product-gap` | `8px` | `8px` | Gap between product cards. |
554
+ | `--aia-product-bg` | `transparent` | `transparent` | Product card background. |
555
+ | `--aia-product-bg-active` | `--aia-option-bg` | `--aia-option-bg` | Product card background on hover. |
556
+ | `--aia-product-media-bg` | `--aia-skeleton-bg` | `--aia-skeleton-bg` | Placeholder fill of the product tile: shown until the photo loads, and behind both fallback tiles (placeholder pictogram or title initial) used when an image URL is missing, blank or fails to load. Once a photo loads the tile is transparent. |
557
+ | `--aia-scroll-arrow-color` | `--aia-option-color` | `--aia-option-color` | Chevron color of the arrow (`--aia-scroll-arrow-color-hover` on hover). |
558
+ | `--aia-placeholder-fade` | `120ms` | `120ms` | Fade-out of the outgoing placeholder phrase when the starting-state placeholder changes (the incoming one types itself in). |
559
+ | `--aia-product-image-radius` | `8px` | `8px` | Corner radius of a product photo narrower than its square tile (a tall one), which is scaled to fit rather than cropped. A photo that fills the tile takes the tile's own 8px corners. |
560
+ | `--aia-product-placeholder-image` | storefront pictogram | storefront pictogram | The pictogram used by `productImageFallback: "image"` (the default) when an image URL is missing, blank or fails to load. Defaults to a two-tone storefront inlined as a data URI. Set any `url(...)` to swap it; it is centered and contained over `--aia-product-media-bg`. Does not affect `"initial"` tiles. |
561
+ | `--aia-product-title-color` | `--aia-option-color-selected` | `--aia-option-color-selected` | Product title text. Follows the option colors by default, so theming the panel moves suggestions and products together. |
562
+ | `--aia-product-price-color` | `--aia-option-color-selected` | `--aia-option-color-selected` | Product price text. |
563
+ | `--aia-product-compare-at-color` | `currentColor` | `currentColor` | The struck price before a markdown. Defaults to the price's colour. |
564
+ | `--aia-product-compare-at-opacity` | `0.6` | `0.6` | How far the struck price is dimmed. |
565
+ | `--aia-product-vendor-color` | `--aia-option-color` | `--aia-option-color` | Product vendor line. |
566
+ | `--aia-product-focus-ring` | `--aia-option-color-selected` | `--aia-option-color-selected` | Focus ring drawn on a keyboard-focused card. |
567
+ | `--aia-products-label-color` | `--aia-option-color` | `--aia-option-color` | "Best match" section label. |
568
+ | `--aia-product-title-font-size` | `12px` | `12px` | Product title font size. |
569
+ | `--aia-product-price-font-size` | `11px` | `11px` | Product price font size. |
570
+ | `--aia-product-vendor-font-size` | `10px` | `10px` | Product vendor font size. |
571
+ | `--aia-products-label-font-size` | `11px` | `11px` | Section label font size. |
572
+ | `--aia-date-panel-width` | `312px` | `312px` | Max width of the whole dropdown panel while the calendar is up — the panel narrows to calendar size. |
573
+ | `--aia-date-cell-size` | `26px` | `26px` | Size of a day's square — the box that carries the highlight, the today ring and the selected fill. |
574
+ | `--aia-date-row-height` | `28px` | `28px` | Height of one week row. Lower it to fit a 6-week month in a shorter dropdown. |
575
+ | `--aia-date-row-min-height` | `20px` | `20px` | The shortest a week row may get when the dropdown is fitted to a short window and the weeks share what is left. Never applies above `--aia-date-row-height`. |
576
+ | `--aia-date-cell-font-size` | `13px` | `13px` | Day-number font size. |
577
+ | `--aia-date-month-font-size` | `14px` | `14px` | Font size of the "March 2026" header. |
578
+ | `--aia-date-weekday-font-size` | `11px` | `11px` | Font size of the S/M/T/W/T/F/S column letters. |
579
+ | `--aia-date-today-ring` | `--aia-option-color` | `--aia-option-color` | Outline drawn around today's date. |
580
+ | `--aia-date-selected-bg` | white at 12% | white at 12% | Fill behind the date a re-edited parameter already holds. |
581
+ | `--aia-date-range-bg` | white at 6% | white at 6% | Band across the days between the two ends of a picked date range. The ends themselves use `--aia-date-selected-bg`. |
582
+ | `--aia-time-panel-width` | `240px` | `240px` | Max width of the whole dropdown panel while the time wheel is up. |
583
+ | `--aia-time-font-size` | `15px` | `15px` | The time wheel's numbers and its `:` separator. |
584
+ | `--aia-time-band-bg` | white at 8% | white at 8% | The band behind the wheels' top rows — the chosen time. |
585
+ | `--aia-time-done-bg` | white at 10% | white at 10% | The time wheel's Done button. |
586
+ | `--aia-time-done-bg-hover` | white at 16% | white at 16% | The Done button on hover. |
587
+ | `--aia-time-done-color` | `--aia-option-color-selected` | `--aia-option-color-selected` | The Done button's text. |
588
+ | `--aia-location-field-bg` | `--aia-streak-rgb` at 6% (indigo) | `--aia-streak-rgb` at 6% (white) | The location search field. |
589
+ | `--aia-location-field-radius` | `10px` | `10px` | Corner radius of the location search field. |
590
+ | `--aia-location-font-size` | `15px` | `15px` | The location field's text and the place names. |
591
+ | `--aia-location-row-bg-highlighted` | `--aia-streak-rgb` at 8% (indigo) | `--aia-streak-rgb` at 8% (white) | The highlighted (or hovered) place. |
592
+ | `--aia-skeleton-bg` | `rgba(189, 189, 189, 0.083)` | `#1a1b1d` | Fill color for the loading skeleton bars and the masked text in cached pills/options, and of the option and chip image tiles while their picture loads (unless `--aia-option-image-bg` / `--aia-chip-image-bg` are set). |
593
+
594
+ Legacy `--aia-color-*` variables are still supported as fallbacks.