@magicx-eng/ai-autocomplete-angular 0.63.1 → 0.64.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/README.md CHANGED
@@ -325,7 +325,7 @@ export class SearchComponent implements OnInit, OnDestroy {
325
325
 
326
326
  > **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.
327
327
 
328
- > **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.
328
+ > **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".
329
329
 
330
330
  ## Convenience NgModule
331
331
 
@@ -362,14 +362,16 @@ Standalone-first apps don't need this: import the components/directive directly.
362
362
  | `optionsPosition` | `"above" \| "below"` | `"below"` | Where the dropdown opens relative to the input. |
363
363
  | `animations` | `boolean` | `true` | All SDK animations: press, shimmer, typed placeholder, staggered options, scroll arrow. `prefers-reduced-motion` stops the last three. |
364
364
  | `optionsStyle` | `"floating" \| "classic"` | `"floating"` | `"classic"`: the old stroke, size and motion. |
365
- | `dropdownTrigger` | `"auto" \| "manual" \| "hidden"` | `"auto"` | When the dropdown appears. `"auto"` = when options available. `"manual"` = only on pill tap, closes after selection. `"hidden"` = never shows. |
366
- | `closeDropdownOnBlur` | `boolean` | `true` | When `true`, the dropdown closes if the input loses focus. Set to `false` to keep it open whenever options are available, regardless of focus. |
365
+ | `dropdownTrigger` | `"auto" \| "manual" \| "hidden"` | `"auto"` | When the dropdown appears. `"auto"`: when options are available. `"manual"`: only on pill tap, closes after selection. `"hidden"`: never. |
366
+ | `closeDropdownOnBlur` | `boolean` | `true` | The dropdown closes when the input loses focus. `false`: it stays open whenever options are available, regardless of focus. |
367
+ | `focusInputOnSelect` | `"auto" \| "always" \| "never"` | `"auto"` | Whether a pick focuses the input. `"auto"`: not on a touch device, where a tapped pick puts the keyboard away. See "On phones" in REFERENCE.md. |
368
+ | `startingState` | `boolean` | `true` | `false`: nothing until the shopper types (REFERENCE.md). |
367
369
  | `prependPlaceholder` | `boolean` | `true` | `false`: hint only. |
368
- | `showNonTappableOptions` | `boolean` | `true` | Non-tappable options are rendered alongside tappable ones in the dropdown. `false`: hide them. |
369
- | `locationSearch` | `boolean` | `true` | When `true`, a location parameter without options searches places as the user types in its field. Set to `false` to take typed text only. See [Location search](#location-search). |
370
- | `showSkipButton` | `boolean` | `true` | The dropdown's pill bar ends in a small "skip" button that dismisses the active pill, as <kbd>→</kbd> at the end of the input does. It sits at the header's trailing edge, across from the label, once the input has text. `false` hides it. |
371
- | `showOptionIcons` | `boolean` | `true` | An option that carries an `icon_svg` draws it before its text in the dropdown. `false`: text only. |
372
- | `showChipIcons` | `boolean` | `true` | A completed chip in the input draws the icon of the option that answered it. `false`: text only. |
370
+ | `showNonTappableOptions` | `boolean` | `true` | Non-tappable options are drawn beside tappable ones in the dropdown. `false`: hide them. |
371
+ | `locationSearch` | `boolean` | `true` | A location parameter without options searches places as the user types in its field. `false`: typed text only. See [Location search](#location-search). |
372
+ | `showSkipButton` | `boolean` | `true` | The dropdown's pill bar ends in a small "skip" button that dismisses the active pill, as <kbd>→</kbd> at the end of the input does. It sits at the header's trailing edge, across from the label, once the input has text. `false`: hidden. |
373
+ | `showOptionIcons` | `boolean` | `true` | An option with an `icon_svg` draws it before its text in the dropdown. `false`: text only. |
374
+ | `showChipIcons` | `boolean` | `true` | A completed chip draws the icon of the option that answered it. `false`: text only. |
373
375
  | `showChipImages` | `boolean` | `true` | A completed chip in the input draws the picture (`image_url`) of the option that answered it, in place of its icon. `false`: no pictures. |
374
376
  | `showChipRemove` | `boolean` | `false` | `true`: every chip (picked, or identified in typed text) ends in a faint × that removes it in one tap. Opacity: `--aia-chip-remove-opacity`, `--aia-chip-remove-opacity-hover`. |
375
377
  | `showOptionImages` | `boolean` | `true` | An option that carries an `image_url` draws it as a square thumbnail before its text in the dropdown, in place of its icon. `false`: no pictures. |
@@ -504,7 +506,7 @@ ac.destroy();
504
506
 
505
507
  #### Constructor options
506
508
 
507
- Accepts the same shape as `<ai-autocomplete>`'s inputs (`apiConfig`, `additionalContext`, `language`, `productId`, `visitorId`, `optionOverrides`, `columns`, `dropdownTrigger`, `optionsPosition`, `closeDropdownOnBlur`, `showNonTappableOptions`, `allOption`, `locationSearch`, `showProducts`, `products`), plus event callbacks (`onSubmit`, `onResult`, `onError`, `onChange`, `onParamsChange`, `onFocus`, `onBlur`, `onProductSelect`), the add-to-cart handler (`onProductAddToCart`, which `update()` can also set, swap or remove) and controlled-mode initial values (`value`, `completedParams`). `onResult` fires after every successful round-trip; see [Reading the query as it's built](#reading-the-query-as-its-built).
509
+ Accepts the same shape as `<ai-autocomplete>`'s inputs (`apiConfig`, `additionalContext`, `language`, `productId`, `visitorId`, `optionOverrides`, `columns`, `dropdownTrigger`, `optionsPosition`, `closeDropdownOnBlur`, `focusInputOnSelect`, `showNonTappableOptions`, `allOption`, `locationSearch`, `showProducts`, `products`), plus event callbacks (`onSubmit`, `onResult`, `onError`, `onChange`, `onParamsChange`, `onFocus`, `onBlur`, `onProductSelect`), the add-to-cart handler (`onProductAddToCart`, which `update()` can also set, swap or remove) and controlled-mode initial values (`value`, `completedParams`). `onResult` fires after each successful round-trip; see [Reading the query as it's built](#reading-the-query-as-its-built).
508
510
 
509
511
  #### State observables
510
512
 
@@ -616,7 +618,8 @@ The structured query as the SDK currently understands it. The same object is emi
616
618
  | `completed_params` | `CompletedParam[]` | Filled parameter values in query order, followed by any the user skipped (see below). |
617
619
  | `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. |
618
620
  | `is_ready` | `boolean` | Whether the server considers the query complete enough to act on. |
619
- | `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. |
621
+ | `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. |
622
+ | `custom_fields_stale?` | `true` | Set when `custom_fields` does not answer this query. See "The filters a submit carries" in REFERENCE.md. |
620
623
 
621
624
  #### Reading the query as it's built
622
625
 
@@ -688,13 +691,13 @@ Every variable, with its default, is listed in [REFERENCE.md](https://unpkg.com/
688
691
 
689
692
  ### Short screens
690
693
 
691
- 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.
694
+ 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.
692
695
 
693
- 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.
696
+ 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.
694
697
 
695
698
  ### Dismissing the keyboard
696
699
 
697
- 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`.
700
+ 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`.
698
701
 
699
702
  ### Selector Hooks
700
703
 
package/REFERENCE.md CHANGED
@@ -2,17 +2,49 @@
2
2
 
3
3
  Longer guides that do not fit in the [README](https://unpkg.com/@magicx-eng/ai-autocomplete-angular/README.md) on the npm page. This file ships in the package, at `node_modules/@magicx-eng/ai-autocomplete-angular/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
  - [Server-side rendering](#server-side-rendering)
13
16
  - [Visitor id kept by the SDK](#visitor-id-kept-by-the-sdk)
14
17
  - [Search id](#search-id)
15
18
 
19
+ ## Starting state
20
+
21
+ 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.
22
+
23
+ ```html
24
+ <ai-autocomplete [startingState]="false" (submitted)="onSubmit($event)"></ai-autocomplete>
25
+ ```
26
+
27
+ `new AIAutocompleteController({ startingState: false })` takes it too.
28
+
29
+ With it off, while nothing is typed and nothing is picked (spaces alone count as nothing):
30
+
31
+ - 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.
32
+ - The dropdown stays closed whatever the focus, `closeDropdownOnBlur` and `dropdownTrigger`: no options, no loading skeleton, no product strip, no "See all results" row.
33
+ - 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.
34
+ - State reads as nothing to show: `isDropdownOpen` is `false`, `suggestions`, the options, `products` and `placeholderText` are empty, and `isLoading` is `false`.
35
+
36
+ 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.
37
+
38
+ 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`.
39
+
40
+ The input can change after mount, and so can `controller.update({ startingState })`: turned off over an empty input, the starting state on screen is cleared at once; turned on, it is requested as on mount.
41
+
42
+ How it differs from the options it is confused with:
43
+
44
+ - `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.
45
+ - `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.
46
+ - `prependPlaceholder: false` keeps the starting state and only stops its lead-in from being written before a pick.
47
+
16
48
  ## Product strip
17
49
 
18
50
  The dropdown renders a horizontal row of product cards below the options grid
@@ -411,6 +443,61 @@ To hide the spinner and keep the behaviour (repeats still ignored, `aria-busy` s
411
443
 
412
444
  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.
413
445
 
446
+ ## The filters a submit carries
447
+
448
+ `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:
449
+
450
+ - 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;
451
+ - the request for the latest text has not come back yet, so the block answers an earlier text.
452
+
453
+ 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.
454
+
455
+ **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".
456
+
457
+ **With `[awaitAnswerOnSubmit]="true"`** a submit (Enter, the arrow button) whose stored block does not answer the submitted query first gets the full answer for it, then calls `(submitted)` with that answer's `custom_fields`, `identified_params` and `is_ready`:
458
+
459
+ ```html
460
+ <ai-autocomplete
461
+ [apiConfig]="apiConfig"
462
+ [awaitAnswerOnSubmit]="true"
463
+ [submitAnswerTimeoutMs]="2500"
464
+ (submitted)="openResults($event.query, $event.custom_fields?.applied_filters ?? [])"
465
+ ></ai-autocomplete>
466
+ ```
467
+
468
+ `new AIAutocompleteController({ ... })` takes the same two options (`awaitAnswerOnSubmit`, `submitAnswerTimeoutMs`); they cover Enter.
469
+
470
+ - 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.
471
+ - That request is an ordinary `/suggest` call, billed like any other. It is sent only with the option on or through `controller.awaitSubmitResult()`, and only when the stored answer is not the submitted query's; with the option off a submit sends nothing.
472
+ - While it waits the submit is in progress: `isSubmitting$` emits `true`, the submit controls show their spinner, and a second submit is ignored. See "While your page loads" above.
473
+ - Typing, picking an option or a product, or a press elsewhere on the page cancels the wait, and `(submitted)` is not called.
474
+ - 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.
475
+ - The wait lasts at most `[submitAnswerTimeoutMs]` (2500 ms by default). When no answer came in time, or the request failed (network error, 4xx, 5xx), `(submitted)` 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`.
476
+ - When the stored block already answers the query, nothing waits and `(submitted)` is called at once.
477
+
478
+ With the option on, a submit never carries `custom_fields_stale`: the block answers the submitted query or is left out.
479
+
480
+ **Your own submit button, on the controller.** `getState()` and `getResult()` read the same stored block, so after `prepareSubmit()` they have the same staleness. `controller.awaitSubmitResult()` prepares the submit and resolves to the result with the answer to it, whatever `awaitAnswerOnSubmit` is set to:
481
+
482
+ ```ts
483
+ async submit(): Promise<void> {
484
+ if (this.controller.getState().isSubmitting) return;
485
+ const result = await this.controller.awaitSubmitResult(); // no custom_fields key when no answer came in time
486
+ if (!result) return; // the shopper changed the input, or a submit is in progress
487
+ this.controller.recordSubmit(result);
488
+ this.controller.holdSubmit(this.openResults(result));
489
+ }
490
+ ```
491
+
492
+ `null` from `controller.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.
493
+
494
+ | | |
495
+ |---|---|
496
+ | `[awaitAnswerOnSubmit]` | `boolean`, default `false`. A submit waits for the answer to its own query before `(submitted)`. Also a controller option. |
497
+ | `[submitAnswerTimeoutMs]` | `number`, default `2500`. The longest that wait lasts, also for `awaitSubmitResult()`. |
498
+ | `controller.awaitSubmitResult()` | `Promise<AutocompleteResult \| null>`. The result to submit from your own button; `null` when there is nothing to submit. |
499
+ | `result.custom_fields_stale` | `true` when `custom_fields` does not answer the result's query; absent otherwise. |
500
+
414
501
  ## Datepicker
415
502
 
416
503
  When the next parameter is a date, the dropdown shows a calendar instead of a
@@ -621,6 +708,39 @@ replaces it.
621
708
 
622
709
  ---
623
710
 
711
+ ## On phones: the keyboard after a pick
712
+
713
+ 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:
714
+
715
+ - The option becomes a chip and the next question shows in the same dropdown, which stays open.
716
+ - If the field was focused, it is blurred, so the keyboard goes down. If it was not, it is left unfocused.
717
+ - 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.
718
+ - 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.
719
+ - 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.
720
+
721
+ On a device whose main pointer is not touch, a pick focuses the field and places the caret after the chip, as before.
722
+
723
+ `[focusInputOnSelect]` changes the rule:
724
+
725
+ | Value | After a pick |
726
+ | --- | --- |
727
+ | `"auto"` (default) | Focus the field on a desktop. On a touch device, put the keyboard away as described above. |
728
+ | `"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. |
729
+ | `"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. |
730
+
731
+ For example, `focusInputOnSelect="always"`. It can change at any time.
732
+
733
+ With `AIAutocompleteController` and `[aiaInput]` you own the field, and the controller takes the same option (`focusInputOnSelect`, also through `controller.update()`). The directive follows the same rule: on a touch device a tapped pick blurs your field, and the directive neither focuses it nor moves its caret. `controller.focusesInputOnSelect()` tells your own code which rule is in force.
734
+
735
+ When `controller.focusesInputOnSelect()` returns `false`, do not focus your field after a pick in your own code. A host that focuses its input after every pick brings the keyboard straight back.
736
+
737
+ 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: `controller.selectOption(option, { fromKeyboard: true })`. Without that, a call with no key press or click behind it counts as a tap.
738
+
739
+ Two things to know before relying on the default:
740
+
741
+ - **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.
742
+ - **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"`.
743
+
624
744
  ## CSS variables
625
745
 
626
746
  Override on the host element (via `class`). The variables are declared with `:where()` (zero specificity), so a value you set on the host always wins.
@@ -716,6 +836,10 @@ The full input also accepts `--aia-input-radius` and `--aia-written-text-font-we
716
836
  | `--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. |
717
837
  | `--aia-footer-chip-bg` | `--aia-surface` at 65% | `--aia-surface` at 65% | Fill behind the footer's keyboard hint and "Powered by Intent-1" badge. The option list scrolls under the footer, so this keeps both legible over the row passing behind them. `transparent` on the glass surface. |
718
838
 
839
+ ### Option pictures and counts
840
+
841
+ 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.
842
+
719
843
  ## Server-side rendering
720
844
 
721
845
  The package is render-blocking-safe — the Tier 1 component renders a static shell during SSR / Angular Universal, and the live autocomplete only mounts on the client. For Tier 2 (`new AIAutocompleteController(...)`), gate construction with `isPlatformBrowser`: