@nxgt/material 3.41.0 → 3.42.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.
@@ -373,7 +373,7 @@ export function Framework() {
373
373
 
374
374
  ![Autocomplete](../previews/selection-choice-autocomplete.webp)
375
375
 
376
- Single or multiple (chips) autocomplete with free-solo values, accent-insensitive matching and a debounced server search.
376
+ Single or multiple (chips) autocomplete with free-solo values, accent-insensitive matching and a debounced server search; a single value can be the input's own text (`display="text"`).
377
377
 
378
378
  ```tsx
379
379
  import { Autocomplete } from '@nxgt/material/components';
@@ -409,6 +409,8 @@ disabled with the field; Backspace in the empty input removes the last one.
409
409
  | Prop | Type | Default | Effect |
410
410
  | --- | --- | --- | --- |
411
411
  | `mode` | `'single' \| 'multiple'` | — | required; decides the `value` type |
412
+ | `display` | `'chip' \| 'text'` | `'chip'` | `mode="single"` only: how the value is drawn, a removable chip beside the input (and its placeholder), or the input's own text (type `AutocompleteDisplay`; see [One value as text](#one-value-as-text)). Ignored in `multiple` |
413
+ | `clearable` | `boolean` | `true` | shows the "Clear" button; with `display="text"`, whether emptying the text and leaving the field clears the value |
412
414
  | `value` | `string` / `string[]` | — | required, per `mode` |
413
415
  | `onValueChange` | `(value?: string \| null) => void` / `(value?: string[] \| null) => void` | — | per `mode` |
414
416
  | `options` | `T[]` (`{ value, label, disabled? }` by default) | `[]` | the items (`disabled` on one: listed, announced as disabled, never picked); with `onSearch`, the list before a search and the selected options' labels |
@@ -435,6 +437,50 @@ An avatar in the rows and the chips:
435
437
  `getOptionLeading={(person) => <Avatar src={person.photo} alt="" />}`; see
436
438
  [the field look](../guides/field-look-2-x.md#autocomplete-and-the-chips-box).
437
439
 
440
+ ### One value as text
441
+
442
+ By default a single value is drawn as a chip, like a multi-select with one
443
+ entry. For picking one entry out of a long directory (a person, a place, a
444
+ resource), `display="text"` makes the chosen option's label the input's own
445
+ text, as a `Select` shows it, and keeps the search:
446
+
447
+ ```tsx
448
+ <Autocomplete
449
+ mode="single"
450
+ display="text"
451
+ label="Member"
452
+ placeholder="Search a member"
453
+ options={selected ? [selected] : []}
454
+ onSearch={searchMembers}
455
+ value={value}
456
+ onValueChange={(next) => setValue(next ?? '')}
457
+ />
458
+ ```
459
+
460
+ - The label fills the input (on the server too); the placeholder shows only
461
+ while the field is empty. The text is selected on focus, so typing replaces
462
+ it and searches again (`onSearch` or the local `filter`); the list opened on
463
+ the label is the whole `options`, not filtered by it.
464
+ - Typing changes nothing until an option is picked. **Escape**, or leaving
465
+ the field (Tab, a click elsewhere), drops the typed text and brings the
466
+ label back; the value never moved. Escape on a closed list does the same
467
+ instead of clearing.
468
+ - The "Clear" button empties the text and the value. Emptying the text by
469
+ hand and leaving the field clears the value too, since the field is
470
+ `clearable`. With `clearable={false}` there is no button, and an emptied text
471
+ gets the label back on leave: the value can only be replaced by another pick.
472
+ - The option's `getOptionLeading` (or `renderSelectedLeading`) avatar shows
473
+ before the text while it is picked.
474
+ - `freeSolo` still adds through its "Add" button; text left in the input and
475
+ not added is dropped on leave, as any other typed text.
476
+ - Keep the selected option in `options` (as with `onSearch` and chips): a value
477
+ with no matching option has no label, so the input stays empty.
478
+ - The input is the combobox: `aria-expanded` follows the list,
479
+ `aria-activedescendant` names the highlighted option, the picked option is
480
+ `aria-selected`, and the field's live region announces the suggestions as
481
+ before. `AutocompleteFormField` takes `display` and `clearable` too. Leaving the
482
+ window (Alt-Tab) is not leaving the field: the typed text waits.
483
+
438
484
  ### Searching a server
439
485
 
440
486
  `onSearch` takes the query and an `AbortSignal`; hand the signal to `fetch`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxgt/material",
3
- "version": "3.41.0",
3
+ "version": "3.42.0",
4
4
  "license": "MIT",
5
5
  "bugs": {
6
6
  "email": "stevegires@gmail.com"