@magicx-eng/ai-autocomplete-vanilla 0.79.1 → 0.80.0

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/README.md CHANGED
@@ -95,10 +95,10 @@ const ac = new AIAutocomplete(container, {
95
95
  optionOverrides: { location: async (query, signal) => [...] }, // see "Option Overrides"
96
96
  columns: 2,
97
97
  maskCompletedText: false, // when true, omits completed params' text from API requests (PII masking)
98
- commitOnWordEnd: false, // true = a word still being typed never becomes a chip until a space, Enter, or Tab ends it (exact matches and server identified params). Picking an option is unchanged.
98
+ commitOnWordEnd: false, // true = a typed word becomes a chip only once a space, Enter or Tab ends it (exact matches and server identified params). Picking an option is unchanged.
99
99
  additionalContext: { tier: "gold" }, // optional user context, to personalize suggestions and options
100
100
  language: "es", // BCP 47 tag sent with every suggestion request and telemetry event. Default: navigator.language, else "en-US"
101
- productId: "...", // your product id: what the dropdown offers before anything is typed is read from a cacheable URL with no credential; falls back to a suggestion request
101
+ productId: "...", // your product id: the starting state is read from a cacheable URL with no credential; falls back to a suggestion request
102
102
 
103
103
  // Appearance
104
104
  mode: "auto", // "light" | "dark" | "auto"
@@ -107,32 +107,34 @@ const ac = new AIAutocomplete(container, {
107
107
  optionsStyle: "floating", // "classic" = the old stroke, size and motion
108
108
  pillPlacement: "dropdown", // "inline" | "dropdown" | "hidden"
109
109
  dropdownTrigger: "auto", // "auto" | "manual" | "hidden"
110
- closeDropdownOnBlur: true, // false = keep dropdown open even when input loses focus
110
+ closeDropdownOnBlur: true, // false = stay open when the input loses focus
111
+ startingState: true, // false = nothing until the shopper types
111
112
  prependPlaceholder: true, // false = show the starting state's lead-in text as a hint only; a picked option is not written after it
112
113
  showNonTappableOptions: true, // false = hide non-tappable options from the dropdown
113
114
  allOption: false, // true = lead a plain question with an All row that skips it
114
115
  locationSearch: true, // false = a location field takes typed text only, no lookups
115
- showSkipButton: true, // false = hide the pill bar's "skip" button (trailing edge)
116
- showOptionIcons: true, // false = render option rows as text only (no icons)
117
- showChipIcons: true, // false = render completed chips as text only (no icons)
118
- showChipImages: true, // false = never draw an option's picture on its completed chip
116
+ showSkipButton: true, // false = hide the pill bar's "skip" button (trailing edge)
117
+ showOptionIcons: true, // false = option rows as text only (no icons)
118
+ showChipIcons: true, // false = completed chips as text only (no icons)
119
+ showChipImages: true, // false = no option picture on its completed chip
119
120
  showChipRemove: false, // true = each chip ends in a small faint × that removes it in one tap
120
121
  showOptionImages: true, // false = never draw an option's image_url thumbnail
121
- showOptionCounts: true, // false = never show an option's item_count
122
+ showOptionCounts: true, // false = hide an option's item_count
122
123
 
123
124
  // Focus
124
125
  autoFocus: true, // focus the input on mount (Tier 1 only)
126
+ focusInputOnSelect: "auto", // a pick focuses the input, except on touch devices, where a tapped pick puts the keyboard away. "always" | "never": see REFERENCE.md
125
127
 
126
- // Where the stylesheet is injected. Defaults to the container's own root —
127
- // the document, or the shadow root when the widget is mounted in one — so
128
- // this is only for sending the styles somewhere else. See "Shadow DOM".
128
+ // Where the stylesheet is injected. Default: the container's own root (the
129
+ // document, or the shadow root the widget is mounted in), so this is only
130
+ // for sending the styles somewhere else. See "Shadow DOM".
129
131
  styleRoot: undefined,
130
132
 
131
133
  // Product strip. Shown by default from the items the /suggest response
132
134
  // reports; false renders no strip.
133
135
  showProducts: true,
134
- // How the strip lays its cards out: a scrolling row, or "list" — the same
135
- // cards stacked as full-width rows.
136
+ // How the strip lays out its cards: a scrolling row, or "list" (the same
137
+ // cards stacked as full-width rows).
136
138
  productsLayout: "row",
137
139
  // Missing/blank URL or load error: "image" (default) or the title initial.
138
140
  productImageFallback: "image",
@@ -181,6 +183,7 @@ Product display options apply to both `renderMode: "full"` and
181
183
  | `productsLayout?` | `"row" \| "list"` | `"row"` | Lay out cards as a scrolling row or a vertical list. |
182
184
  | `seeAllResults?` | `boolean` | `false` | Tier 1 only (React's `<AIAutocomplete>` has it too). End the dropdown in a "See all results" button that submits like Enter, shown while there is typed text. The dropdown then keeps its full width at every step. It shows a spinner while its submit is in progress. |
183
185
  | `submitProgress?` | `boolean` | `true` | Show a spinner and ignore repeats on a submit or product tap while your page loads. `false` turns it off. See "While your page loads" in REFERENCE.md. |
186
+ | `awaitAnswerOnSubmit?` | `boolean` | `false` | A submit waits for the answer to its own query. See "The filters a submit carries" in REFERENCE.md. |
184
187
  | `productImageFallback?` | `"image" \| "initial"` | `"image"` | Fallback for a missing or blank product image URL, or an image load error. `"image"` shows the placeholder pictogram; `"initial"` shows the title initial. A working image still takes priority. See [Product strip](#product-strip). |
185
188
  | `showProductVendor?` | `boolean` | `true` | Whether product cards draw the product's `vendor` as a line above the title. Set to `false` when your product titles already name the brand, so a card does not show it twice. See [Product strip](#product-strip). |
186
189
 
@@ -197,6 +200,7 @@ ac.selectProduct(product); // Emit onProductSelect (Tier 3 / custom strips)
197
200
  ac.addProductToCart(product); // Call onProductAddToCart (Tier 3 / custom strips)
198
201
  ac.prepareSubmit(); // Prepare the typed word before your own button builds a result
199
202
  ac.getResult(); // The AutocompleteResult as it stands right now
203
+ ac.awaitSubmitResult(); // Async: the result to submit, with its answer
200
204
  ac.getRequestId(); // The latest applied /suggest request ID, or null
201
205
  ```
202
206
 
@@ -358,7 +362,7 @@ unsub();
358
362
 
359
363
  > **Option icons.** An option may carry an icon: `icon_svg` is inline SVG markup and `icon` its name. The built-in dropdown draws the SVG before the option's text, in the text color. When rendering options yourself, pass `icon_svg` through the exported `sanitizeOptionIconSvg` before inserting it — it reduces the markup to plain vector drawing and returns `null` for anything else — and use `optionLabel(option)` for the text — it is the option's `text` alone; `icon` is the icon's name and is never shown as text, even when `icon_svg` is missing or fails to draw. A picked option's `icon` / `icon_svg` are copied onto its completed parameter, and the chip in the input draws the glyph before its text. Both surfaces can be switched off: `showOptionIcons: false` renders option rows as text only and `showChipIcons: false` renders chips as text only; either way the icon element is omitted rather than hidden.
360
364
 
361
- > **Option pictures and counts.** An option may also carry `image_url` — a picture of the best-matching catalog item offering it — and `item_count`, how many items offer it (each is present only when the server includes it; when it includes counts, the options also arrive ordered by them, most items first; a starting state carries pictures but no counts). The built-in dropdown draws the picture as a square thumbnail before the option's text (in place of its `icon_svg`, so a row never leads with two visuals) and the count as a muted label at the row's trailing edge (`"12 items"`). Icons and pictures are all-or-nothing per list: if any tappable option would draw neither, no row draws one, so a list never mixes rows with and without a leading visual (non-tappable rows don't count). A custom dropdown can apply the same rule with the exported `optionsShowLeadingVisuals(options, showIcons, showImages)`. The unit word after the number is a token: set `--aia-option-count-unit: "sneakers"` to name what is being counted, `--aia-option-count-unit-one: "sneaker"` for a count of 1 (it falls back to the plural token), or `--aia-option-count-unit: ""` for the number alone. When rendering options yourself, pass `image_url` through the exported `optionImageSrc` before using it as an `<img src>` — it returns the URL only when it is `http(s)` and `null` otherwise — and `formatOptionCount(option.item_count)` gives the number the built-in rows print (`null` when there is no count); `optionCountLabel(count, unit?)` appends a unit for a dropdown that prints the word itself (`"item"` / `"items"` by default; one word, a `{ one, other }` pair, or `""` for none). Both surfaces can be switched off: `showOptionImages: false` renders rows without pictures (an option's icon then draws instead) and `showOptionCounts: false` hides the counts. A picked option's `image_url` is copied onto its completed parameter too, and the chip in the input draws it as a small rounded tile before its text, in place of the icon; `showChipImages: false` renders chips without pictures (the icon then draws instead). The tile is sized by `--aia-option-image-size` (40px), rounded by `--aia-option-image-radius` (12px), spaced by `--aia-option-image-gap` (12px) and filled by `--aia-option-image-bg` (default: `--aia-skeleton-bg`) as a placeholder until its picture loads (or if the picture fails); a loaded picture is scaled to fit rather than cropped and sits on the dropdown's background, and one narrower than the tile is rounded on its own corners by `--aia-option-picture-radius` (6px); in a grid with pictures, an icon row draws its glyph at `--aia-option-tile-icon-size` (1.5em) so it holds the picture column; the count reads `--aia-option-count-font-size` (12px), `--aia-option-count-color` and `--aia-option-count-opacity` (0.6); the chip's tile reads `--aia-chip-image-size` (1.25em of the chip's font), `--aia-chip-image-radius` (4px) and `--aia-chip-image-bg` (default: `--aia-skeleton-bg`), the placeholder fill shown until the picture loads; a loaded picture narrower than the tile narrows it to the picture's own width, so the radius rounds the picture.
365
+ > **Option pictures and counts.** An option may also carry `image_url` — a picture of the best-matching catalog item offering it — and `item_count`, how many items offer it (each is present only when the server includes it; when it includes counts, the options also arrive ordered by them, most items first; a starting state carries pictures but no counts). The built-in dropdown draws the picture as a square thumbnail before the option's text (in place of its `icon_svg`, so a row never leads with two visuals) and the count as a muted label at the row's trailing edge (`"12 items"`). Icons and pictures are all-or-nothing per list: if any tappable option would draw neither, no row draws one, so a list never mixes rows with and without a leading visual (non-tappable rows don't count). A custom dropdown can apply the same rule with the exported `optionsShowLeadingVisuals(options, showIcons, showImages)`. The unit word after the number is a token: set `--aia-option-count-unit: "sneakers"` to name what is being counted, `--aia-option-count-unit-one: "sneaker"` for a count of 1 (it falls back to the plural token), or `--aia-option-count-unit: ""` for the number alone. When rendering options yourself, pass `image_url` through the exported `optionImageSrc` before using it as an `<img src>` — it returns the URL only when it is `http(s)` and `null` otherwise — and `formatOptionCount(option.item_count)` gives the number the built-in rows print (`null` when there is no count); `optionCountLabel(count, unit?)` appends a unit for a dropdown that prints the word itself (`"item"` / `"items"` by default; one word, a `{ one, other }` pair, or `""` for none). Both surfaces can be switched off: `showOptionImages: false` renders rows without pictures (an option's icon then draws instead) and `showOptionCounts: false` hides the counts. A picked option's `image_url` is copied onto its completed parameter too, and the chip in the input draws it as a small rounded tile before its text, in place of the icon; `showChipImages: false` renders chips without pictures (the icon then draws instead). Its size and colour tokens are in REFERENCE.md, under "Option pictures and counts".
362
366
 
363
367
  > **Removing a chip.** With `showChipRemove: true`, every chip in the input ends in a small, faint "×"; one tap or click on it removes that chip, the same result as Backspace at the chip's trailing edge (`removeParam(id)` does the same from code). Chips the server identified in typed text get one too. The × reads `--aia-chip-remove-opacity` (0.32) and `--aia-chip-remove-opacity-hover` (0.7).
364
368
 
@@ -409,7 +413,7 @@ unsub();
409
413
  | `removeParam(paramId)` | Remove the chip with that id (completed or identified), the same result as Backspace at the chip's trailing edge; the chip's × (`showChipRemove`) calls it. Any value's id of one multi-select answer removes its joined chip. Returns `false`, changing nothing, when no chip has that id. |
410
414
  | `clearNewParamId()` | Clear shimmer animation state. |
411
415
  | `reset()` | Clear all state, re-fetch initial suggestions, and start a new session (rotates `session_id`). Call this after handling submit. |
412
- | `prepareSubmit()` | Call before building a submit result from your own button. A typed word that equals exactly one completion candidate becomes a completed param, the same as Enter. A typed value the response returned with no pill yet (`state: "need_confirmation"`) joins `identifiedParams` if the text has not changed since that response. A submit that skips this call leaves that value out. Read the updated state with `getState()` to build the result. |
416
+ | `prepareSubmit()` | Call before building a submit result from your own button: a typed word equal to exactly one completion candidate becomes a completed param, as on Enter, and a typed value returned with no pill yet (`state: "need_confirmation"`) joins `identifiedParams` if the text is unchanged since. Then read `getState()`, or use `awaitSubmitResult()`. |
413
417
  | `recordSubmit(result)` | Record a submit from a button you render. Enter and the built-in button are recorded for you; call this once per submit from your own button. |
414
418
  | `setValue(text)` | Set text (controlled mode). Text set this way is not reported as the user starting a search. |
415
419
  | `prefillText(text)` | Fill the field with text the user did not type — e.g. a query carried over from the previous page — and handle it like typing: suggestions are fetched and the text is recognized. Not reported as the user starting a search. |
@@ -502,7 +506,8 @@ The structured query as the SDK currently understands it. The same object is pas
502
506
  | `completed_params` | `CompletedParam[]` | Filled parameter values in query order, followed by any the user skipped (see below). |
503
507
  | `identified_params` | `IdentifiedParam[]` | Parameters the server recognised in the user's own words, as `{ parameter, text }` — e.g. `{ parameter: "due_date", text: "Friday" }` when the user typed "by Friday" instead of picking a date. They are not tokenized in `raw_query`, and they are tentative: each response replaces the set, and an entry drops out as soon as its text is edited away. |
504
508
  | `is_ready` | `boolean` | Whether the server considers the query complete enough to act on. |
505
- | `custom_fields?` | `CustomFieldsReport` | What catalog grounding did for the latest applied response, when it read a catalog at all — see [Product strip](#product-strip). `applied_filters` and `dropped_filters` list the query's constraints as `{ parameter, value, op }`; `items.total` is how many items the applied ones left standing and `items.matched` the ones the strip renders. Absent (no key) when the response carried no report. |
509
+ | `custom_fields?` | `CustomFieldsReport` | The catalog report of the latest applied response (`applied_filters`, `dropped_filters`, `items`) — see [Product strip](#product-strip). Absent (no key) when the response carried none. |
510
+ | `custom_fields_stale?` | `true` | Set when `custom_fields` does not answer this query. See "The filters a submit carries" in REFERENCE.md. |
506
511
 
507
512
  #### Reading the query as it's built
508
513
 
@@ -620,13 +625,13 @@ document.getElementById("my-autocomplete")
620
625
 
621
626
  ### Short screens
622
627
 
623
- When the open dropdown would run past the edge of the visible screen — most often a phone with its on-screen keyboard up, or a short browser window — it shrinks to the space that is left and scrolls as one: the options and the product strip move together, so scrolling down past the last option brings the products into view. The pill bar scrolls with them. Each time the dropdown opens it checks again, and while it is open it follows the keyboard opening and closing and the page scrolling.
628
+ When the open dropdown would run past the edge of the visible screen (most often a phone with its on-screen keyboard up, or a short browser window), it shrinks to the space left and scrolls as one: the options, the product strip and the pill bar move together, so scrolling past the last option brings the products into view. It checks again each time it opens, and while open it follows the keyboard opening and closing and the page scrolling.
624
629
 
625
- While fitted, the dropdown root carries `data-aia-fit`, and the height it is capped at is in its `--aia-dropdown-fit-height` property. Every option shows in that one scroll, so the option list's usual limit of visible rows does not apply.
630
+ While fitted, the dropdown root carries `data-aia-fit`, and its capped height is in its `--aia-dropdown-fit-height` property. Every option shows in that one scroll, so the option list's usual limit of visible rows does not apply.
626
631
 
627
632
  ### Dismissing the keyboard
628
633
 
629
- On a phone or tablet, the shopper can put the keyboard away to see the whole dropdown: a tap on the page, or the keyboard's own done / hide key, closes the keyboard and leaves the dropdown open. The next tap outside the search box and dropdown closes it. Scrolling the page doesn't, and neither does tapping inside the dropdown. A tap on a link, button or other field outside it is treated as moving on, and closes the dropdown straight away as before. With a mouse, a click outside closes the dropdown at once, as it always has. While the dropdown is held open this way, `isDropdownOpen` stays `true` and `isFocused` is `false`.
634
+ On a phone or tablet, the shopper can put the keyboard away to see the whole dropdown: a tap on the page, or the keyboard's own done / hide key, closes the keyboard and leaves the dropdown open. The next tap outside the search box and dropdown closes it; scrolling the page or tapping inside the dropdown does not. A tap on a link, button or other field outside it counts as moving on and closes the dropdown at once, as before. With a mouse, a click outside closes it at once, as always. While held open this way, `isDropdownOpen` stays `true` and `isFocused` is `false`.
630
635
 
631
636
  ### Selector Hooks
632
637
 
package/REFERENCE.md CHANGED
@@ -2,16 +2,48 @@
2
2
 
3
3
  Longer guides that do not fit in the [README](https://unpkg.com/@magicx-eng/ai-autocomplete-vanilla/README.md) on the npm page. This file ships in the package, at `node_modules/@magicx-eng/ai-autocomplete-vanilla/REFERENCE.md`.
4
4
 
5
+ - [Starting state](#starting-state)
5
6
  - [Product strip](#product-strip)
6
7
  - [While your page loads](#while-your-page-loads)
8
+ - [The filters a submit carries](#the-filters-a-submit-carries)
7
9
  - [Datepicker](#datepicker)
8
10
  - [Time picker](#time-picker)
9
11
  - [Multiple selections](#multiple-selections)
10
12
  - [Location search](#location-search)
13
+ - [On phones: the keyboard after a pick](#on-phones-the-keyboard-after-a-pick)
11
14
  - [CSS variables](#css-variables)
12
15
  - [Visitor id kept by the SDK](#visitor-id-kept-by-the-sdk)
13
16
  - [Search id](#search-id)
14
17
 
18
+ ## Starting state
19
+
20
+ By default the SDK asks for your product's starting state when it mounts and whenever the input is empty again, and shows it while the input has focus: the opening question with its options, the lead-in text and rotating hint inside the box, and any items. Set `startingState` to `false` when shoppers should type first, for example when most of them start with a brand name and the opening question would lead them through several steps.
21
+
22
+ ```js
23
+ const ac = new AIAutocomplete(document.querySelector("#search"), {
24
+ startingState: false,
25
+ });
26
+ ```
27
+
28
+ With it off, while nothing is typed and nothing is picked (spaces alone count as nothing):
29
+
30
+ - No request is made: not on mount, not when the text is deleted or the last chip removed, not after `reset()`. That covers both the cacheable starting-state URL (`productId`) and the empty suggestion request, so no impression of a starting state is sent either.
31
+ - The dropdown stays closed whatever the focus, `closeDropdownOnBlur` and `dropdownTrigger`: no options, no loading skeleton, no product strip, no "See all results" row.
32
+ - The SDK writes nothing in the box: no lead-in text, no typed placeholder, no rotating hint. An answer to typed text does not bring a lead-in back, so `prependPlaceholder` has nothing to act on.
33
+ - State reads as nothing to show: `isDropdownOpen` is `false`, `suggestions`, the options, `products` and `placeholderText` are empty, and `isLoading` is `false`.
34
+
35
+ From the first typed character everything works as it does by default: the request goes out after the usual debounce (two or more new characters after 100ms, a single character after 300ms), and the dropdown opens with its answer. No starting question is on screen, so typed text never filters one: "Ki" is sent like any other text instead of narrowing a "Kids" option. When the box is cleared, the dropdown closes and the last answer is dropped in the same update; a request still on its way is ignored.
36
+
37
+ With `awaitAnswerOnSubmit` (or `awaitSubmitResult()`), a submit of typed text waits for its answer as usual. A submit of the empty input has no answer to wait for: it goes out at once, with no `custom_fields`.
38
+
39
+ `update({ startingState })` switches it at runtime: turned off over an empty input, the starting state on screen is cleared at once; turned on, it is requested as on mount.
40
+
41
+ How it differs from the options it is confused with:
42
+
43
+ - `autoFocus` only decides whether the input takes focus on mount. With `autoFocus: false` the starting state is still requested, and it opens as soon as the shopper taps the input.
44
+ - `dropdownTrigger: "manual"` and `"hidden"` close the dropdown for typed text too, and the starting state is still requested. `startingState: false` hides only the starting state.
45
+ - `prependPlaceholder: false` keeps the starting state and only stops its lead-in from being written before a pick.
46
+
15
47
  ## Product strip
16
48
 
17
49
  The dropdown renders a horizontal row of product cards below the options grid
@@ -402,6 +434,59 @@ To hide the spinner and keep the behaviour (repeats still ignored, `aria-busy` s
402
434
 
403
435
  The same selectors take any other rule, for a look of your own: a dimmed card (`[data-aia-product][data-aia-product-state="busy"] { opacity: 0.6; }`), a different animation, a label change.
404
436
 
437
+ ## The filters a submit carries
438
+
439
+ `custom_fields` on a result is the catalog report of the last response the SDK applied. On a submit that response is often not an answer to the query being submitted:
440
+
441
+ - the dropdown was showing completions of the word being typed. Their block reads no filters from the query (`applied_filters: []`), and Enter then turns the typed word into a completed param the block knows nothing about;
442
+ - the request for the latest text has not come back yet, so the block answers an earlier text.
443
+
444
+ A shopper who types `jackets men` and presses Enter at once is in the first case; one who types a space and waits is in neither, which is why this is easy to miss in testing. A results page built from such a block loses the filters the query expressed.
445
+
446
+ **By default** the submit is handed over at once, as before, and such a block is marked: the result carries `custom_fields_stale: true` beside it. Read `applied_filters` and `items` only when the mark is absent, and treat a marked block as "no filters known".
447
+
448
+ **With `awaitAnswerOnSubmit: true`** a submit (Enter, the arrow button, "See all results") whose stored block does not answer the submitted query first gets the full answer for it, then calls `onSubmit` with that answer's `custom_fields`, `identified_params` and `is_ready`:
449
+
450
+ ```ts
451
+ const ac = new AIAutocomplete(container, {
452
+ apiConfig: { apiKey: "..." },
453
+ awaitAnswerOnSubmit: true, // wait for the answer to the submitted query
454
+ submitAnswerTimeoutMs: 2500, // the default
455
+ onSubmit: (result) => openResults(result.query, result.custom_fields?.applied_filters ?? []),
456
+ });
457
+ ```
458
+
459
+ - A request already on the wire for the same query is waited for; otherwise one goes out at once, past the typing debounce. It asks for the whole answer, not for completions.
460
+ - That request is an ordinary `/suggest` call, billed like any other. It is sent only with the option on or through `ac.awaitSubmitResult()`, and only when the stored answer is not the submitted query's; with the option off a submit sends nothing.
461
+ - While it waits the submit is in progress: `getState().isSubmitting` is `true`, the submit controls show their spinner, and a second submit is ignored. See "While your page loads" above.
462
+ - Typing, picking an option or a product, or a press elsewhere on the page cancels the wait, and `onSubmit` is not called.
463
+ - Escape in the widget's own input does not cancel the wait: the submit still goes out when its answer arrives. Change the text to call it off.
464
+ - The wait lasts at most `submitAnswerTimeoutMs` (2500 ms by default). When no answer came in time, or the request failed (network error, 4xx, 5xx), `onSubmit` is called once with **no `custom_fields` key**, never with the earlier block. Treat a missing block as "no filters known" and fall back to a text search on `query`.
465
+ - When the stored block already answers the query, nothing waits and `onSubmit` is called at once.
466
+
467
+ With the option on, a submit never carries `custom_fields_stale`: the block answers the submitted query or is left out.
468
+
469
+ **Your own submit button (Tier 2 or 3).** `getState()` and `getResult()` read the same stored block, so after `prepareSubmit()` they have the same staleness. `ac.awaitSubmitResult()` prepares the submit and resolves to the result with the answer to it, whatever `awaitAnswerOnSubmit` is set to:
470
+
471
+ ```ts
472
+ button.addEventListener("click", async () => {
473
+ if (ac.getState().isSubmitting) return;
474
+ const result = await ac.awaitSubmitResult(); // no custom_fields key when no answer came in time
475
+ if (!result) return; // the shopper changed the input, or a submit is in progress
476
+ ac.recordSubmit(result);
477
+ ac.holdSubmit(openResults(result));
478
+ });
479
+ ```
480
+
481
+ `null` from `ac.awaitSubmitResult()` is not an error. It means there is nothing to submit now: the shopper changed the input, picked a product or pressed elsewhere while it waited, or a submit is already in progress (a repeat press, or Enter's own submit still waiting). Return quietly; do not report it or fall back to another submit.
482
+
483
+ | | |
484
+ |---|---|
485
+ | `awaitAnswerOnSubmit?` | `boolean`, default `false`. A submit waits for the answer to its own query before `onSubmit`. `ac.update({ awaitAnswerOnSubmit })` switches it. |
486
+ | `submitAnswerTimeoutMs?` | `number`, default `2500`. The longest that wait lasts, also for `awaitSubmitResult()`. |
487
+ | `ac.awaitSubmitResult()` | `Promise<AutocompleteResult \| null>`. The result to submit from your own button; `null` when there is nothing to submit. |
488
+ | `result.custom_fields_stale` | `true` when `custom_fields` does not answer the result's query; absent otherwise. |
489
+
405
490
  ## Datepicker
406
491
 
407
492
  When the next parameter is a date, the dropdown shows a calendar instead of a
@@ -621,6 +706,39 @@ call `ac.setLocationFieldFocused(true)` *before* moving focus into it (and
621
706
 
622
707
  ---
623
708
 
709
+ ## On phones: the keyboard after a pick
710
+
711
+ On a touch device (one whose main pointer is a finger: `(hover: none) and (pointer: coarse)`) the keyboard covers part of the dropdown. So a tapped pick puts the keyboard away, and it stays away while the shopper answers:
712
+
713
+ - The option becomes a chip and the next question shows in the same dropdown, which stays open.
714
+ - If the field was focused, it is blurred, so the keyboard goes down. If it was not, it is left unfocused.
715
+ - The same holds for the All row, a checkbox row and Done on a checkbox list, a calendar date, the time picker and the skip button. A pill tapped in the dropdown's pill bar does not focus the field either.
716
+ - The keyboard comes back when the shopper taps the field (the caret goes to the end of the text) or taps a chip to re-edit it. A chip's "×", the submit button and "See all results" work without it. The next tap outside the dropdown closes it.
717
+ - A pick made from the keyboard keeps focus in the field, with the caret after the new chip: arrow keys and Enter (on a hardware keyboard for instance), and any option, skip, Done, day or place activated without a pointer (Enter or Space on it, switch control, assistive technology that activates the element directly). A click that carries no click count (`event.detail === 0`) is read as one of these.
718
+
719
+ On a device whose main pointer is not touch, a pick focuses the field and places the caret after the chip, as before.
720
+
721
+ `focusInputOnSelect` changes the rule:
722
+
723
+ | Value | After a pick |
724
+ | --- | --- |
725
+ | `"auto"` (default) | Focus the field on a desktop. On a touch device, put the keyboard away as described above. |
726
+ | `"always"` | Focus the field on every device. On a phone the keyboard stays up, or comes up, after each pick. This was the behaviour before `"auto"` existed. |
727
+ | `"never"` | A pick never focuses the field. On a touch device a tapped pick still puts the keyboard away, as with `"auto"`. On a desktop a focused field stays focused and an unfocused one stays unfocused: a tap on a pill in the dropdown's pill bar does not focus it either, so the shopper clicks the field before typing. |
728
+
729
+ For example, `focusInputOnSelect: "always"`. `ac.update({ focusInputOnSelect })` changes it at any time.
730
+
731
+ With `renderMode: "dropdown"` or `"headless"` you own the input. The same rule applies to it as long as you report its focus and blur (`setFocused()`): on a touch device a tapped pick blurs your input, and the SDK does not focus it. If your own code focuses the input after a selection, skip that on a touch device.
732
+
733
+ `ac.focusesInputOnSelect()` tells your own code which rule is in force: when it returns `false`, do not focus your input after a pick. A host that focuses its input after every pick brings the keyboard straight back.
734
+
735
+ A pick your own code makes while a key press is being handled (Enter in your own `keydown` listener) is read as a keyboard pick too, and keeps focus. If the pick happens later than the key press (after a timer or a request), say so yourself: `ac.selectOption(option, { fromKeyboard: true })`. Without that, a call with no key press or click behind it counts as a tap.
736
+
737
+ Two things to know before relying on the default:
738
+
739
+ - **A tablet with a mouse or trackpad** still reports a touch main pointer, so a mouse click on an option there counts as a tap and blurs the field. `"always"` is the opt-out.
740
+ - **Screen readers.** A pick activated without a pointer keeps focus in the field (see above). A screen reader that activates an option by sending a touch, as a double-tap usually does, counts as a tap: nothing holds focus afterwards, it goes to the document body, and the user's position leaves the field until they move back to it. If that matters more to you than the keyboard covering the options, use `"always"`.
741
+
624
742
  ## CSS variables
625
743
 
626
744
  Override these on the container element. The variables are declared with `:where()` (zero specificity), so a value you set on the container always wins without `!important`.
@@ -727,6 +845,10 @@ The full input also accepts `--aia-input-radius` and `--aia-written-text-font-we
727
845
  | `--aia-chip-remove-opacity` | `0.32` | `0.32` | Opacity of a chip's remove × (`showChipRemove`). The × is for a mouse or a tap and is hidden from assistive technology; from the keyboard, Backspace at the end of a chip removes it. |
728
846
  | `--aia-chip-remove-opacity-hover` | `0.7` | `0.7` | Opacity of that × under a hovering pointer (never on touch). |
729
847
 
848
+ ### Option pictures and counts
849
+
850
+ Tokens for the option thumbnail, the item count and the chip's picture (the README's "Option pictures and counts" note describes what each draws). The tile is sized by `--aia-option-image-size` (40px), rounded by `--aia-option-image-radius` (12px), spaced by `--aia-option-image-gap` (12px) and filled by `--aia-option-image-bg` (default: `--aia-skeleton-bg`) as a placeholder until its picture loads (or if the picture fails); a loaded picture is scaled to fit rather than cropped and sits on the dropdown's background, and one narrower than the tile is rounded on its own corners by `--aia-option-picture-radius` (6px); in a grid with pictures, an icon row draws its glyph at `--aia-option-tile-icon-size` (1.5em) so it holds the picture column; the count reads `--aia-option-count-font-size` (12px), `--aia-option-count-color` and `--aia-option-count-opacity` (0.6); the chip's tile reads `--aia-chip-image-size` (1.25em of the chip's font), `--aia-chip-image-radius` (4px) and `--aia-chip-image-bg` (default: `--aia-skeleton-bg`), the placeholder fill shown until the picture loads; a loaded picture narrower than the tile narrows it to the picture's own width, so the radius rounds the picture.
851
+
730
852
  ## Visitor id kept by the SDK
731
853
 
732
854
  Without `visitorId`, the SDK can keep the id for you. Pass `analyticsConsent` so it knows the visitor's choice: `true` (allowed), `false` (declined), or `undefined` (not answered yet). Once allowed, it keeps a UUID v4 in the first-party cookie `aia_vid` for a year, renewed on use; declined, it removes that cookie. This needs the feature to be enabled for your account, and nothing is stored without `analyticsConsent`.