@eifi1/ui-kit 0.22.0 → 0.23.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.
Files changed (205) hide show
  1. package/README.md +42 -25
  2. package/dist/chart.d.ts +11 -8
  3. package/dist/components/amount-input.d.ts +28 -8
  4. package/dist/components/amount-input.js +3 -1
  5. package/dist/components/amount-input.js.map +1 -1
  6. package/dist/components/autocomplete.d.ts +21 -0
  7. package/dist/components/autocomplete.js +128 -103
  8. package/dist/components/autocomplete.js.map +1 -1
  9. package/dist/components/button-group.d.ts +11 -8
  10. package/dist/components/calculator.d.ts +11 -8
  11. package/dist/components/column-mapper.d.ts +182 -0
  12. package/dist/components/column-mapper.js +375 -0
  13. package/dist/components/column-mapper.js.map +1 -0
  14. package/dist/components/combobox-core.d.ts +39 -2
  15. package/dist/components/combobox-core.js +29 -6
  16. package/dist/components/combobox-core.js.map +1 -1
  17. package/dist/components/combobox.d.ts +80 -2
  18. package/dist/components/combobox.js +448 -311
  19. package/dist/components/combobox.js.map +1 -1
  20. package/dist/components/confirm-dialog.d.ts +11 -8
  21. package/dist/components/confirm-dialog.js +7 -8
  22. package/dist/components/confirm-dialog.js.map +1 -1
  23. package/dist/components/copy-button.d.ts +8 -5
  24. package/dist/components/country-select.d.ts +50 -7
  25. package/dist/components/country-select.js +65 -9
  26. package/dist/components/country-select.js.map +1 -1
  27. package/dist/components/danger-confirm.d.ts +11 -8
  28. package/dist/components/danger-confirm.js +13 -3
  29. package/dist/components/danger-confirm.js.map +1 -1
  30. package/dist/components/date-picker.d.ts +41 -0
  31. package/dist/components/date-picker.js +269 -8
  32. package/dist/components/date-picker.js.map +1 -1
  33. package/dist/components/entity-combobox.d.ts +35 -1
  34. package/dist/components/entity-combobox.js +148 -112
  35. package/dist/components/entity-combobox.js.map +1 -1
  36. package/dist/components/facing-pair.d.ts +11 -8
  37. package/dist/components/field-parts.d.ts +116 -6
  38. package/dist/components/field-parts.js +84 -0
  39. package/dist/components/field-parts.js.map +1 -1
  40. package/dist/components/field-strip.d.ts +105 -0
  41. package/dist/components/field-strip.js +46 -0
  42. package/dist/components/field-strip.js.map +1 -0
  43. package/dist/components/file-button.d.ts +11 -8
  44. package/dist/components/file-dropzone.d.ts +11 -8
  45. package/dist/components/form-actions.d.ts +10 -7
  46. package/dist/components/form-actions.js +8 -2
  47. package/dist/components/form-actions.js.map +1 -1
  48. package/dist/components/iban-input.d.ts +11 -8
  49. package/dist/components/icon-picker.d.ts +10 -1
  50. package/dist/components/icon-picker.js +12 -4
  51. package/dist/components/icon-picker.js.map +1 -1
  52. package/dist/components/language-select.d.ts +11 -8
  53. package/dist/components/money-field.d.ts +14 -8
  54. package/dist/components/money-field.js.map +1 -1
  55. package/dist/components/month-picker.js +2 -1
  56. package/dist/components/month-picker.js.map +1 -1
  57. package/dist/components/multi-entity-combobox.d.ts +26 -1
  58. package/dist/components/multi-entity-combobox.js +143 -102
  59. package/dist/components/multi-entity-combobox.js.map +1 -1
  60. package/dist/components/number-field.d.ts +11 -8
  61. package/dist/components/number-input.d.ts +11 -8
  62. package/dist/components/numpad-sheet.d.ts +11 -8
  63. package/dist/components/phone-input.d.ts +11 -8
  64. package/dist/components/reauth-dialog.d.ts +2 -2
  65. package/dist/components/reauth-dialog.js +6 -8
  66. package/dist/components/reauth-dialog.js.map +1 -1
  67. package/dist/components/series-chart.d.ts +11 -8
  68. package/dist/components/settings-fields.d.ts +11 -8
  69. package/dist/components/share-card.d.ts +10 -7
  70. package/dist/components/swatch-picker.d.ts +17 -1
  71. package/dist/components/swatch-picker.js +10 -4
  72. package/dist/components/swatch-picker.js.map +1 -1
  73. package/dist/components/text-link.d.ts +10 -7
  74. package/dist/components/tile-radio.d.ts +20 -0
  75. package/dist/components/tile-radio.js +25 -8
  76. package/dist/components/tile-radio.js.map +1 -1
  77. package/dist/components/time-input.d.ts +11 -8
  78. package/dist/components/toggle-group.js +2 -2
  79. package/dist/components/toggle-group.js.map +1 -1
  80. package/dist/components/trigger-aria.d.ts +3 -0
  81. package/dist/components/trigger-aria.js +3 -1
  82. package/dist/components/trigger-aria.js.map +1 -1
  83. package/dist/components/ui.d.ts +8 -5
  84. package/dist/components/ui.js +5 -11
  85. package/dist/components/ui.js.map +1 -1
  86. package/dist/feedback/feedback-attachment.d.ts +1 -1
  87. package/dist/feedback/feedback-attachment.js +156 -56
  88. package/dist/feedback/feedback-attachment.js.map +1 -1
  89. package/dist/feedback/feedback-dialog.d.ts +1 -1
  90. package/dist/feedback/feedback-dialog.js.map +1 -1
  91. package/dist/feedback/feedback-inbox.d.ts +3 -2
  92. package/dist/feedback/feedback-inbox.js.map +1 -1
  93. package/dist/feedback/feedback-thread.d.ts +68 -287
  94. package/dist/feedback/feedback-thread.js +8 -1
  95. package/dist/feedback/feedback-thread.js.map +1 -1
  96. package/dist/{kit-labels-R8mIAc9N.d.ts → feedback-BxeQVzwq.d.ts} +405 -22
  97. package/dist/{feedback-attachment-NhUm7Zga.d.ts → feedback-attachment-fGAzZPf0.d.ts} +112 -10
  98. package/dist/feedback.d.ts +66 -2
  99. package/dist/hooks/use-file-drop.d.ts +11 -8
  100. package/dist/i18n/defaults.d.ts +11 -8
  101. package/dist/i18n/defaults.js +3 -1
  102. package/dist/i18n/defaults.js.map +1 -1
  103. package/dist/i18n/german.d.ts +11 -8
  104. package/dist/i18n/german.js +36 -2
  105. package/dist/i18n/german.js.map +1 -1
  106. package/dist/i18n/kit-labels.d.ts +7 -4
  107. package/dist/i18n/kit-labels.js.map +1 -1
  108. package/dist/i18n/languages.d.ts +11 -8
  109. package/dist/i18n/locales/de-CH.d.ts +11 -8
  110. package/dist/i18n/locales/en.d.ts +11 -8
  111. package/dist/i18n/locales/en.js +7 -0
  112. package/dist/i18n/locales/en.js.map +1 -1
  113. package/dist/i18n/locales/es.d.ts +11 -8
  114. package/dist/i18n/locales/es.js +37 -2
  115. package/dist/i18n/locales/es.js.map +1 -1
  116. package/dist/i18n/locales/fr.d.ts +11 -8
  117. package/dist/i18n/locales/fr.js +36 -2
  118. package/dist/i18n/locales/fr.js.map +1 -1
  119. package/dist/i18n/locales/hu.d.ts +11 -8
  120. package/dist/i18n/locales/hu.js +38 -2
  121. package/dist/i18n/locales/hu.js.map +1 -1
  122. package/dist/i18n/locales/it.d.ts +11 -8
  123. package/dist/i18n/locales/it.js +37 -2
  124. package/dist/i18n/locales/it.js.map +1 -1
  125. package/dist/i18n/locales/zh.d.ts +11 -8
  126. package/dist/i18n/locales/zh.js +34 -2
  127. package/dist/i18n/locales/zh.js.map +1 -1
  128. package/dist/i18n/review.d.ts +11 -8
  129. package/dist/i18n/review.js +20 -1
  130. package/dist/i18n/review.js.map +1 -1
  131. package/dist/index.d.ts +7 -3
  132. package/dist/index.js +16 -0
  133. package/dist/index.js.map +1 -1
  134. package/dist/lib/column-mapping.d.ts +81 -0
  135. package/dist/lib/column-mapping.js +108 -0
  136. package/dist/lib/column-mapping.js.map +1 -0
  137. package/dist/lib/table-text.d.ts +109 -1
  138. package/dist/lib/table-text.js +122 -1
  139. package/dist/lib/table-text.js.map +1 -1
  140. package/dist/rhf/fields.d.ts +89 -11
  141. package/dist/rhf/fields.js +124 -0
  142. package/dist/rhf/fields.js.map +1 -1
  143. package/dist/rhf/form.d.ts +11 -8
  144. package/dist/rhf.d.ts +12 -9
  145. package/dist/rhf.js.map +1 -1
  146. package/dist/shell/app-shell.d.ts +10 -7
  147. package/dist/shell/top-bar-brand.d.ts +11 -8
  148. package/dist/shell/topbar-action-menu.d.ts +36 -3
  149. package/dist/shell/topbar-action-menu.js +74 -33
  150. package/dist/shell/topbar-action-menu.js.map +1 -1
  151. package/dist/shell.d.ts +10 -7
  152. package/dist/table-text.d.ts +1 -1
  153. package/dist/wizard/stepper-nav.d.ts +41 -10
  154. package/dist/wizard/stepper-nav.js +4 -0
  155. package/dist/wizard/stepper-nav.js.map +1 -1
  156. package/dist/wizard.d.ts +11 -8
  157. package/package.json +1 -1
  158. package/src/components/amount-input.tsx +20 -1
  159. package/src/components/autocomplete.tsx +172 -111
  160. package/src/components/column-mapper.tsx +666 -0
  161. package/src/components/combobox-core.tsx +82 -9
  162. package/src/components/combobox.tsx +614 -332
  163. package/src/components/confirm-dialog.tsx +12 -8
  164. package/src/components/country-select.tsx +135 -22
  165. package/src/components/danger-confirm.tsx +91 -12
  166. package/src/components/date-picker.tsx +423 -10
  167. package/src/components/entity-combobox.tsx +217 -126
  168. package/src/components/field-parts.tsx +224 -5
  169. package/src/components/field-strip.tsx +149 -0
  170. package/src/components/form-actions.tsx +32 -4
  171. package/src/components/icon-picker.tsx +23 -4
  172. package/src/components/money-field.tsx +3 -0
  173. package/src/components/month-picker.tsx +2 -1
  174. package/src/components/multi-entity-combobox.tsx +207 -120
  175. package/src/components/reauth-dialog.tsx +17 -18
  176. package/src/components/swatch-picker.tsx +29 -5
  177. package/src/components/tile-radio.tsx +74 -13
  178. package/src/components/toggle-group.tsx +2 -2
  179. package/src/components/trigger-aria.ts +5 -0
  180. package/src/components/ui.tsx +7 -33
  181. package/src/feedback/feedback-attachment.tsx +308 -61
  182. package/src/feedback/feedback-dialog.tsx +7 -3
  183. package/src/feedback/feedback-inbox.tsx +3 -2
  184. package/src/feedback/feedback-thread.tsx +47 -4
  185. package/src/i18n/defaults.ts +2 -0
  186. package/src/i18n/german.ts +42 -0
  187. package/src/i18n/kit-labels.tsx +4 -0
  188. package/src/i18n/locales/en.ts +27 -5
  189. package/src/i18n/locales/es.ts +41 -0
  190. package/src/i18n/locales/fr.ts +42 -0
  191. package/src/i18n/locales/hu.ts +37 -0
  192. package/src/i18n/locales/it.ts +41 -0
  193. package/src/i18n/locales/zh.ts +32 -0
  194. package/src/i18n/review.ts +19 -0
  195. package/src/index.ts +18 -0
  196. package/src/lib/column-mapping.ts +234 -0
  197. package/src/lib/table-text.ts +271 -0
  198. package/src/rhf/fields.tsx +254 -0
  199. package/src/rhf.ts +2 -1
  200. package/src/shell/topbar-action-menu.tsx +134 -38
  201. package/src/wizard/stepper-nav.tsx +35 -1
  202. package/dist/components/field-anatomy.d.ts +0 -95
  203. package/dist/components/field-anatomy.js +0 -84
  204. package/dist/components/field-anatomy.js.map +0 -1
  205. package/src/components/field-anatomy.tsx +0 -190
@@ -1,7 +1,7 @@
1
1
  import { Fragment, useId, useMemo, useRef, useState } from "react";
2
2
  import type { ComponentPropsWithoutRef, ReactNode, RefObject } from "react";
3
3
  import { createPortal } from "react-dom";
4
- import { ChevronDown, X } from "lucide-react";
4
+ import { ChevronDown, Plus, X } from "lucide-react";
5
5
  import { FIELD_BASE, FIELD_FLOATING_PAD, FIELD_INVALID, PHONE_QUERY } from "./ui";
6
6
  import { cn } from "../lib/cn";
7
7
  import { useDropdown } from "./dropdown";
@@ -12,7 +12,9 @@ import { PickerSheet, SHEET_ROW_CLASS } from "./picker-sheet";
12
12
  import {
13
13
  ComboboxFieldLabel,
14
14
  DISABLED_ROW_CLASS,
15
+ endHintRowProps,
15
16
  isOptionEnabled,
17
+ offersCreate,
16
18
  stepEnabled,
17
19
  SUGGESTION_LIST_CLASS,
18
20
  suggestionRowClass,
@@ -22,7 +24,17 @@ import {
22
24
  type ComboOption,
23
25
  } from "./combobox-core";
24
26
  import { DEFAULT_COMBOBOX_LABELS, useKitLabels } from "../i18n/kit-labels";
25
- import { EndHintRow, FieldCaption, LABEL_IN_ROW, StaticLabelRow, useFieldHint } from "./field-parts";
27
+ import {
28
+ EndHintRow,
29
+ FieldCaption,
30
+ LABEL_IN_ROW,
31
+ LockedReason,
32
+ StaticLabelRow,
33
+ useFieldHint,
34
+ useLockReason,
35
+ } from "./field-parts";
36
+ import { hasMessage, mergeDescribedBy } from "./choice-parts";
37
+ import { useCommitReason } from "./write-lock";
26
38
 
27
39
  // One look for both combobox flavors below — the suggestion list and its rows
28
40
  // must stay pixel-identical between the free-text and the id-keyed variant (and
@@ -124,6 +136,27 @@ function SuggestionList({
124
136
 
125
137
  const rowClass = suggestionRowClass;
126
138
 
139
+ /**
140
+ * The write lock on the two TYPED fields below — {@link Button}'s `disabledReason`
141
+ * path, for an input (keksdose G2).
142
+ *
143
+ * `readOnly` rather than `disabled`, as everywhere the kit locks a field: still focusable,
144
+ * so the reason in the Tooltip reaches a keyboard; refusing keys, so nothing typed can
145
+ * become a value; and FIELD_BASE paints a `[readonly]` field in the settled grey a
146
+ * disabled one wears. No list opens, by focus, click, chevron or arrow — and Enter is
147
+ * swallowed, so a locked field does not submit the form around it either (Select's
148
+ * lock, `LOCKED_SELECT_KEYS`). Every other key is left alone: the arrows and Home/End
149
+ * still move the caret through a long value someone is trying to read.
150
+ */
151
+ function lockedKeyDown(e: { key: string; preventDefault: () => void }) {
152
+ if (e.key === "Enter") e.preventDefault();
153
+ }
154
+
155
+ /** {@link InlineEntityCombobox}'s create row over the shared row look: in the brand
156
+ * colour {@link Combobox}'s own create row wears, with a leading "+" as the panel
157
+ * pickers' has — an action at the foot of the list, not one more record. */
158
+ const CREATE_ROW_CLASS = "flex items-center gap-2 font-medium text-[var(--brand)]";
159
+
127
160
  /**
128
161
  * Four of the div's own attributes are omitted because this component already owns
129
162
  * the name, with a different meaning: `id` is the INPUT's (a caller labels or
@@ -163,6 +196,18 @@ export interface ComboboxProps
163
196
  * stops toggling with it — it is a mouse target the input's own `disabled` does
164
197
  * not reach. */
165
198
  disabled?: boolean;
199
+ /**
200
+ * Why the value cannot be changed — {@link Button}'s `disabledReason`, for a field
201
+ * that SAVES itself (an inline editor whose blur writes). The input stays focusable
202
+ * and `aria-disabled`, is `readOnly`, opens no list and calls neither `onChange` nor
203
+ * `onSubmit`; the reason is in the kit {@link Tooltip} and on its `aria-describedby`.
204
+ * Wins over `disabled`. The family's lock (keksdose G2) — see {@link InlineEntityCombobox}.
205
+ */
206
+ disabledReason?: ReactNode;
207
+ /** This field COMMITS. Under a locked {@link WriteLockProvider} it is locked the
208
+ * `disabledReason` way with the lock's reason; inside a form with its own Save, leave
209
+ * it off and put `commit` on the Save. No provider, or an unlocked one: no effect. */
210
+ commit?: boolean;
166
211
  /** Heading an option belongs under. Supplying it makes this list read exactly
167
212
  * like {@link InlineEntityCombobox}'s — one heading per group with its rows
168
213
  * indented beneath — instead of a flat list (feedback #136 rework: the payee
@@ -227,36 +272,39 @@ export interface ComboboxProps
227
272
  * visually and behaviourally consistent with the other dropdowns (feedback
228
273
  * #230 — the payee field looked/behaved differently from every other select).
229
274
  */
230
- export function Combobox({
231
- value,
232
- onChange,
233
- options,
234
- label,
235
- id,
236
- placeholder,
237
- className,
238
- groupBy,
239
- maxSuggestions,
240
- searchPlaceholder,
241
- closeLabel,
242
- createLabel,
243
- invalid,
244
- error,
245
- hint,
246
- disabled,
247
- optionAdornment,
248
- autoFocus,
249
- onBlur,
250
- onSubmit,
251
- "aria-label": ariaLabel,
252
- // Off `rest` and onto the <input>, which is the combobox a reader meets: `Field`'s
253
- // render-prop spreads `{ id, aria-describedby, aria-invalid, aria-required }`, and
254
- // on the wrapper div the hint and required state described nothing.
255
- "aria-describedby": ariaDescribedBy,
256
- "aria-invalid": ariaInvalid,
257
- "aria-required": ariaRequired,
258
- ...rest
259
- }: ComboboxProps) {
275
+ export function Combobox(props: ComboboxProps) {
276
+ const {
277
+ value,
278
+ onChange,
279
+ options,
280
+ label,
281
+ id,
282
+ placeholder,
283
+ className,
284
+ groupBy,
285
+ maxSuggestions,
286
+ searchPlaceholder,
287
+ closeLabel,
288
+ createLabel,
289
+ invalid,
290
+ error,
291
+ hint,
292
+ disabled,
293
+ disabledReason,
294
+ commit,
295
+ optionAdornment,
296
+ autoFocus,
297
+ onBlur,
298
+ onSubmit,
299
+ "aria-label": ariaLabel,
300
+ // Off `rest` and onto the <input>, which is the combobox a reader meets: `Field`'s
301
+ // render-prop spreads `{ id, aria-describedby, aria-invalid, aria-required }`, and
302
+ // on the wrapper div the hint and required state described nothing.
303
+ "aria-describedby": ariaDescribedBy,
304
+ "aria-invalid": ariaInvalid,
305
+ "aria-required": ariaRequired,
306
+ ...rest
307
+ } = props;
260
308
  const hintParts = useFieldHint(hint, ariaDescribedBy);
261
309
  const field = useComboboxFieldError(
262
310
  error,
@@ -276,6 +324,12 @@ export function Combobox({
276
324
  const { open, setOpen, wrapperRef, panelRef } = useDropdown({ backCloses: !isPhone });
277
325
  const primaryOnly = usePrimaryPressOnly();
278
326
  const [active, setActive] = useState(-1);
327
+ // The lock (see `lockedKeyDown`): a lock arriving while the list is up closes it,
328
+ // adjusted while rendering so no frame offers a row that can no longer be taken.
329
+ const lock = useLockReason(commit, disabledReason);
330
+ const locked = lock.locked;
331
+ const inert = locked || Boolean(disabled);
332
+ if (locked && open) setOpen(false);
279
333
  // A phone opens the list as a full-screen sheet with its own input, the way a
280
334
  // native <select> does — live #200: "Paid as full screen dialog with input.
281
335
  // Similar to the account select that already appears as full screen." The
@@ -361,7 +415,8 @@ export function Combobox({
361
415
  return heads;
362
416
  }, [matches, groupBy]);
363
417
 
364
- const commit = (v: string) => {
418
+ const take = (v: string) => {
419
+ if (locked) return;
365
420
  onChange(v);
366
421
  setOpen(false);
367
422
  setActive(-1);
@@ -381,6 +436,17 @@ export function Combobox({
381
436
  const activeId = !isPhone && active >= 0 && active < matches.length ? optionId(active) : undefined;
382
437
  useActiveOptionScroll(activeId);
383
438
 
439
+ // While locked the field sits in the reason's Tooltip — in a fragment with a hidden
440
+ // copy of the reason, Button's anatomy; `block` so a full-width field stays full width.
441
+ const withLock = (box: ReactNode) =>
442
+ locked ? (
443
+ <LockedReason lock={lock} className="block">
444
+ {box}
445
+ </LockedReason>
446
+ ) : (
447
+ box
448
+ );
449
+
384
450
  const typed = value.trim();
385
451
  const createRow =
386
452
  createLabel && typed.length > 0 && !options.some((o) => o.toLowerCase() === typed.toLowerCase())
@@ -398,139 +464,148 @@ export function Combobox({
398
464
  name a reader hears is the same words either way. With a "?" it moves into a
399
465
  row after the field, below. */}
400
466
  {label !== undefined && hintParts.labelHint === undefined && (
401
- <ComboboxFieldLabel htmlFor={fieldId} className={disabled ? "opacity-50" : undefined}>
467
+ <ComboboxFieldLabel htmlFor={fieldId} className={inert ? "opacity-50" : undefined}>
402
468
  {label}
403
469
  </ComboboxFieldLabel>
404
470
  )}
405
- <EndHintRow hint={label === undefined ? hintParts.labelHint : undefined}>
406
- {/* The chevron centers against this inner wrapper, which hugs the input.
407
- The outer div can be taller than the input (as a grid item it
408
- stretches to the row height, e.g. next to the editor's category cell
409
- with its split button), which used to drag a top-1/2 chevron down to
410
- the input's bottom edge (feedback #248). */}
411
- {/* Dimmed as a whole when disabled, the way EntityCombobox dims its trigger.
412
- FIELD_BASE's grey alone left a disabled picker looking like a filled-in
413
- one beside the pickers that do dim (the label is not the input's `peer`,
414
- so it is dimmed by hand above). */}
415
- <div ref={fieldRef} className={cn("relative", disabled && "cursor-not-allowed opacity-50")}>
416
- <input
417
- id={fieldId}
418
- value={value}
419
- placeholder={placeholder}
420
- // The caller's name, over the <label for> above — which is what names the
421
- // field otherwise (dev#477: a field with neither announces only its text).
422
- aria-label={ariaLabel}
423
- role="combobox"
424
- aria-expanded={open}
425
- // The list this field is the mouth of. Required by the role, and the half
426
- // that was missing: the field said it was expanded and never said what it
427
- // had expanded, so a reader had no way from the box to the options
428
- // (ESLint's `role-has-required-aria-props`, the audit's §a11y).
429
- aria-controls={listboxId}
430
- aria-activedescendant={activeId}
431
- aria-autocomplete="list"
432
- aria-invalid={field.isInvalid || undefined}
433
- aria-describedby={field.describedBy}
434
- aria-required={ariaRequired}
435
- autoComplete="off"
436
- disabled={disabled}
437
- // eslint-disable-next-line jsx-a11y/no-autofocus -- a documented prop the caller opts into (off by default); the field never takes focus on its own.
438
- autoFocus={autoFocus}
439
- onBlur={onBlur}
440
- onMouseDown={primaryOnly.onMouseDown}
441
- onFocus={() => {
442
- // A back/forward mouse button focuses this field on its way to
443
- // navigating; it is not a request to open anything (live #309 rework).
444
- if (primaryOnly.fromAuxButton()) return;
445
- setOpen(true);
446
- setTyping(false);
447
- // The sheet carries its own input, so the field behind it must not also
448
- // pull up the keyboard and scroll the page under the dialog.
449
- if (isPhone) sheetInputRef.current?.focus();
450
- }}
451
- // A CLICK as well as focus — the other half of dev#549. Picking a suggestion
452
- // closes the list without moving focus (the rows suppress `mousedown` on
453
- // purpose, so the input never blurred), which means clicking the field again
454
- // fires no `focus` event at all and the list stayed shut. "Does not open
455
- // anything" was literally true.
456
- onClick={() => {
457
- setOpen(true);
458
- setTyping(false);
459
- }}
460
- // `inputMode="none"` rather than readOnly: the field must not look
461
- // uneditable (FIELD_BASE greys a read-only field since dev#468) and must
462
- // still take focus — it just has no keyboard of its own, the same trick
463
- // the amount field uses for the numpad.
464
- inputMode={isPhone ? "none" : undefined}
465
- onChange={(e) => {
466
- onChange(e.target.value);
467
- setOpen(true);
468
- setActive(-1);
469
- setTyping(true);
470
- }}
471
- onKeyDown={(e) => {
472
- if (e.key === "ArrowDown") {
473
- e.preventDefault();
471
+ <EndHintRow {...endHintRowProps("hint" in props, label !== undefined, hintParts.labelHint)}>
472
+ {withLock(
473
+ /* The chevron centers against this inner wrapper, which hugs the input.
474
+ The outer div can be taller than the input (as a grid item it
475
+ stretches to the row height, e.g. next to the editor's category cell
476
+ with its split button), which used to drag a top-1/2 chevron down to
477
+ the input's bottom edge (feedback #248).
478
+ Dimmed as a whole when disabled (or locked), the way EntityCombobox dims its
479
+ trigger. FIELD_BASE's grey alone left a disabled picker looking like a
480
+ filled-in one beside the pickers that do dim (the label is not the input's
481
+ `peer`, so it is dimmed by hand above). */
482
+ <div ref={fieldRef} className={cn("relative", inert && "cursor-not-allowed opacity-50")}>
483
+ <input
484
+ id={fieldId}
485
+ value={value}
486
+ placeholder={placeholder}
487
+ // The caller's name, over the <label for> above — which is what names the
488
+ // field otherwise (dev#477: a field with neither announces only its text).
489
+ aria-label={ariaLabel}
490
+ role="combobox"
491
+ aria-expanded={open}
492
+ // The list this field is the mouth of. Required by the role, and the half
493
+ // that was missing: the field said it was expanded and never said what it
494
+ // had expanded, so a reader had no way from the box to the options
495
+ // (ESLint's `role-has-required-aria-props`, the audit's §a11y).
496
+ aria-controls={listboxId}
497
+ aria-activedescendant={activeId}
498
+ aria-autocomplete="list"
499
+ aria-invalid={field.isInvalid || undefined}
500
+ aria-describedby={mergeDescribedBy(field.describedBy, locked && lock.reasonId)}
501
+ aria-required={ariaRequired}
502
+ autoComplete="off"
503
+ // Locked: focusable, `readOnly`, `aria-disabled` — see `lockedKeyDown`.
504
+ disabled={locked ? undefined : disabled}
505
+ readOnly={locked || undefined}
506
+ aria-disabled={locked || undefined}
507
+ // eslint-disable-next-line jsx-a11y/no-autofocus -- a documented prop the caller opts into (off by default); the field never takes focus on its own.
508
+ autoFocus={autoFocus}
509
+ onBlur={onBlur}
510
+ onMouseDown={primaryOnly.onMouseDown}
511
+ onFocus={() => {
512
+ // A back/forward mouse button focuses this field on its way to
513
+ // navigating; it is not a request to open anything (live #309 rework).
514
+ // A locked field takes focus to say why, and opens nothing.
515
+ if (primaryOnly.fromAuxButton() || locked) return;
474
516
  setOpen(true);
475
- setActive((i) => Math.min(i + 1, matches.length - 1));
476
- } else if (e.key === "ArrowUp") {
477
- e.preventDefault();
478
- setActive((i) => Math.max(i - 1, 0));
479
- } else if (e.key === "Enter") {
480
- if (open && active >= 0 && active < matches.length) {
517
+ setTyping(false);
518
+ // The sheet carries its own input, so the field behind it must not also
519
+ // pull up the keyboard and scroll the page under the dialog.
520
+ if (isPhone) sheetInputRef.current?.focus();
521
+ }}
522
+ // A CLICK as well as focus — the other half of dev#549. Picking a suggestion
523
+ // closes the list without moving focus (the rows suppress `mousedown` on
524
+ // purpose, so the input never blurred), which means clicking the field again
525
+ // fires no `focus` event at all and the list stayed shut. "Does not open
526
+ // anything" was literally true.
527
+ onClick={() => {
528
+ if (locked) return;
529
+ setOpen(true);
530
+ setTyping(false);
531
+ }}
532
+ // `inputMode="none"` rather than readOnly: the field must not look
533
+ // uneditable (FIELD_BASE greys a read-only field since dev#468) and must
534
+ // still take focus — it just has no keyboard of its own, the same trick
535
+ // the amount field uses for the numpad.
536
+ inputMode={isPhone ? "none" : undefined}
537
+ onChange={(e) => {
538
+ if (locked) return;
539
+ onChange(e.target.value);
540
+ setOpen(true);
541
+ setActive(-1);
542
+ setTyping(true);
543
+ }}
544
+ onKeyDown={(e) => {
545
+ if (locked) return lockedKeyDown(e);
546
+ if (e.key === "ArrowDown") {
547
+ e.preventDefault();
548
+ setOpen(true);
549
+ setActive((i) => Math.min(i + 1, matches.length - 1));
550
+ } else if (e.key === "ArrowUp") {
481
551
  e.preventDefault();
482
- commit(matches[active]);
483
- } else {
484
- // No row highlighted: the typed text is the answer. `preventDefault`
485
- // only when a caller is taking Enter, so a plain form submit is
486
- // otherwise left alone.
487
- if (onSubmit) e.preventDefault();
552
+ setActive((i) => Math.max(i - 1, 0));
553
+ } else if (e.key === "Enter") {
554
+ if (open && active >= 0 && active < matches.length) {
555
+ e.preventDefault();
556
+ take(matches[active]);
557
+ } else {
558
+ // No row highlighted: the typed text is the answer. `preventDefault`
559
+ // only when a caller is taking Enter, so a plain form submit is
560
+ // otherwise left alone.
561
+ if (onSubmit) e.preventDefault();
562
+ setOpen(false);
563
+ onSubmit?.();
564
+ }
565
+ } else if (e.key === "Escape") {
566
+ setOpen(false);
567
+ setActive(-1);
568
+ } else if (e.key === "Tab") {
569
+ // Closes, and lets the browser take the Tab: focus is in THIS input,
570
+ // which is staying, so there is nothing to catch — unlike the pickers
571
+ // whose focus sits inside a portalled panel.
488
572
  setOpen(false);
489
- onSubmit?.();
573
+ setActive(-1);
490
574
  }
491
- } else if (e.key === "Escape") {
492
- setOpen(false);
493
- setActive(-1);
494
- } else if (e.key === "Tab") {
495
- // Closes, and lets the browser take the Tab: focus is in THIS input,
496
- // which is staying, so there is nothing to catch — unlike the pickers
497
- // whose focus sits inside a portalled panel.
498
- setOpen(false);
499
- setActive(-1);
500
- }
501
- // Home/End are deliberately absent. The APG gives them to the list only
502
- // where the combobox is not editable; here the text IS the value, a
503
- // payee name is long enough to want the caret moved to its start, and
504
- // the desktop list is capped at 8 rows — so jumping it would be worth
505
- // almost nothing and would cost the one gesture that field is used with.
506
- }}
507
- className={cn(
508
- FIELD_BASE,
509
- label !== undefined && FIELD_FLOATING_PAD,
510
- "pe-9",
511
- field.isInvalid && FIELD_INVALID,
512
- )}
513
- />
514
- <ChevronDown
515
- aria-hidden
516
- onMouseDown={(e) => {
517
- // Toggle on the chevron without stealing focus from the input.
518
- e.preventDefault();
519
- if (!disabled) setOpen((o) => !o);
520
- }}
521
- className={cn(
522
- "absolute end-2.5 top-1/2 size-4 -translate-y-1/2 text-[var(--text-placeholder)]",
523
- // The box above does the dimming; dimming here too would halve it again.
524
- !disabled && "cursor-pointer",
525
- )}
526
- />
527
- </div>
575
+ // Home/End are deliberately absent. The APG gives them to the list only
576
+ // where the combobox is not editable; here the text IS the value, a
577
+ // payee name is long enough to want the caret moved to its start, and
578
+ // the desktop list is capped at 8 rows — so jumping it would be worth
579
+ // almost nothing and would cost the one gesture that field is used with.
580
+ }}
581
+ className={cn(
582
+ FIELD_BASE,
583
+ label !== undefined && FIELD_FLOATING_PAD,
584
+ "pe-9",
585
+ field.isInvalid && FIELD_INVALID,
586
+ )}
587
+ />
588
+ <ChevronDown
589
+ aria-hidden
590
+ onMouseDown={(e) => {
591
+ // Toggle on the chevron without stealing focus from the input.
592
+ e.preventDefault();
593
+ if (!inert) setOpen((o) => !o);
594
+ }}
595
+ className={cn(
596
+ "absolute end-2.5 top-1/2 size-4 -translate-y-1/2 text-[var(--text-placeholder)]",
597
+ // The box above does the dimming; dimming here too would halve it again.
598
+ !inert && "cursor-pointer",
599
+ )}
600
+ />
601
+ </div>,
602
+ )}
528
603
  </EndHintRow>
529
604
  {/* The label and its "?" share the top strip — after the field in the DOM, so the
530
605
  "?" follows the control in the tab order, as it does on Input and Select. */}
531
606
  {label !== undefined && hintParts.labelHint !== undefined && (
532
607
  <StaticLabelRow hint={hintParts.labelHint}>
533
- <ComboboxFieldLabel htmlFor={fieldId} className={cn(LABEL_IN_ROW, disabled && "opacity-50")}>
608
+ <ComboboxFieldLabel htmlFor={fieldId} className={cn(LABEL_IN_ROW, inert && "opacity-50")}>
534
609
  {label}
535
610
  </ComboboxFieldLabel>
536
611
  </StaticLabelRow>
@@ -539,7 +614,7 @@ export function Combobox({
539
614
  {field.errorEl}
540
615
  {isPhone && (
541
616
  <PickerSheet
542
- open={open && !disabled}
617
+ open={open && !inert}
543
618
  onClose={() => setOpen(false)}
544
619
  title={label}
545
620
  // The sheet's input IS the field: this is a free-text control, so what is
@@ -564,7 +639,7 @@ export function Combobox({
564
639
  type="button"
565
640
  role="option"
566
641
  aria-selected={false}
567
- onClick={() => commit(typed)}
642
+ onClick={() => take(typed)}
568
643
  className={cn(SHEET_ROW_CLASS, "font-medium text-[var(--brand)]")}
569
644
  >
570
645
  {createRow}
@@ -588,7 +663,7 @@ export function Combobox({
588
663
  type="button"
589
664
  role="option"
590
665
  aria-selected={o === value}
591
- onClick={() => commit(o)}
666
+ onClick={() => take(o)}
592
667
  className={cn(
593
668
  SHEET_ROW_CLASS,
594
669
  optionAdornment && "flex items-center justify-between gap-2",
@@ -604,7 +679,7 @@ export function Combobox({
604
679
  </ul>
605
680
  </PickerSheet>
606
681
  )}
607
- {!isPhone && open && !disabled && (matches.length > 0 || createRow) && (
682
+ {!isPhone && open && !inert && (matches.length > 0 || createRow) && (
608
683
  <SuggestionList id={listboxId} anchorRef={fieldRef} panelRef={panelRef}>
609
684
  {createRow && (
610
685
  <li role="presentation">
@@ -617,7 +692,7 @@ export function Combobox({
617
692
  // mousedown, like the rows below: the input's blur would otherwise
618
693
  // close the list before the click landed.
619
694
  e.preventDefault();
620
- commit(typed);
695
+ take(typed);
621
696
  }}
622
697
  className={cn(rowClass(false), "font-medium text-[var(--brand)]")}
623
698
  >
@@ -657,7 +732,7 @@ export function Combobox({
657
732
  // mousedown (not click) so the blur from the input firing first
658
733
  // doesn't close the list before the selection registers.
659
734
  e.preventDefault();
660
- commit(o);
735
+ take(o);
661
736
  }}
662
737
  onMouseEnter={() => setActive(i)}
663
738
  className={cn(
@@ -729,6 +804,72 @@ export interface InlineEntityComboboxProps<V extends string | number, C extends
729
804
  * affordance both shells share, and it clears without opening anything. */
730
805
  clearable?: boolean;
731
806
  clearLabel?: string;
807
+ /**
808
+ * Why the choice cannot be changed — {@link Button}'s `disabledReason`, for a picker
809
+ * that SAVES on change. keksdose G2: the statement review's account picker IS the
810
+ * write (picking re-runs the duplicate check on the server), and on the read-only demo
811
+ * the app wrapped it in a hand-made Tooltip over a native `disabled` — out of the tab
812
+ * order, so the reason never reached a keyboard.
813
+ *
814
+ * With a reason the input stays focusable and `aria-disabled`, is `readOnly` (the
815
+ * settled grey), opens no list or sheet, offers no clear "×", and no pick, typed
816
+ * label or clear reaches `onChange`; the reason is in the kit {@link Tooltip} and on
817
+ * the input's `aria-describedby`. Wins over `disabled`. Use it CONTROLLED, as the
818
+ * component always is: the shown label is `value`'s.
819
+ */
820
+ disabledReason?: ReactNode;
821
+ /**
822
+ * This picker COMMITS — choosing saves. Under a locked {@link WriteLockProvider} it is
823
+ * locked the `disabledReason` way with the lock's reason (which wins over its own).
824
+ * A picker inside a form with its own Save stays editable under the lock — leave this
825
+ * off there and put `commit` on the Save. No provider, or an unlocked one: no effect.
826
+ */
827
+ commit?: boolean;
828
+ /**
829
+ * A last row that makes a new record from what was typed — keksdose G9, whose "Create
830
+ * cash account" had to become a separate button because this picker had no such row.
831
+ *
832
+ * Shown while the typed query is non-empty and names no option exactly
833
+ * (case-insensitive — an exact hit is a record the list already shows), worded
834
+ * `createLabel(query)`, default `combobox.create`: "Create “{query}”". The arrow keys
835
+ * reach it like an option; Enter or a click calls `onCreate(query)` and closes the
836
+ * list. Making the record, and then passing its id as `value`, is the caller's: the
837
+ * field shows the old selection until it does.
838
+ *
839
+ * The same rule as {@link EntityCombobox}'s `onCreate`, so the family agrees. It is a
840
+ * row of the LIST, not an option: it is never `aria-selected`, never matched by a
841
+ * typed label on blur, and never sorted among the records the way a sentinel option
842
+ * would be (the reason keksdose gave for the separate button).
843
+ */
844
+ onCreate?: (query: string) => void;
845
+ /** The create row's words for a query. Default: `combobox.create` from the
846
+ * {@link UiKitProvider}, else English `Create “{query}”`. */
847
+ createLabel?: (query: string) => string;
848
+ /**
849
+ * Offer the create row with NOTHING typed too, worded as this — keksdose's "Create cash
850
+ * account", which mints an account under a default name and so needs no query.
851
+ * `onCreate` then receives `""`, and the caller supplies the name. Left out, the row
852
+ * needs a query.
853
+ *
854
+ * One string rather than a switch: a row with no query has nothing to quote, so the
855
+ * kit cannot word it — "Create “”" says nothing — and naming it is what turns it on.
856
+ * With both, one handler serves both rows:
857
+ *
858
+ * ```tsx
859
+ * onCreate={(name) => createCash(name || t("cash_account_default_name"))}
860
+ * createEmptyLabel={t("create_cash_account")}
861
+ * ```
862
+ */
863
+ createEmptyLabel?: string;
864
+ /**
865
+ * The create row WRITES while picking does not — keksdose dev#496: on the read-only
866
+ * demo choosing the cash account is draft state and stays live, minting one is a
867
+ * write. Under a locked {@link WriteLockProvider} the row stays in the list, dimmed and
868
+ * passed over by the arrows, with the lock's reason as its second line (a hover is the
869
+ * one explanation a phone cannot show), and `onCreate` is not called. Not needed with
870
+ * `commit`: a locked field opens no list at all.
871
+ */
872
+ createCommit?: boolean;
732
873
  }
733
874
 
734
875
  /**
@@ -749,34 +890,43 @@ export interface InlineEntityComboboxProps<V extends string | number, C extends
749
890
  * sheet that emptied it to show the full list would read as "the user cleared the
750
891
  * field" the moment it closed.
751
892
  */
752
- export function InlineEntityCombobox<V extends string | number, C extends ComboClearValue = null>({
753
- value: rawValue,
754
- onChange,
755
- clearValue = null as C,
756
- options,
757
- label,
758
- id,
759
- placeholder,
760
- className,
761
- disabled,
762
- autoFocus,
763
- searchPlaceholder,
764
- emptyLabel,
765
- closeLabel,
766
- clearable,
767
- clearLabel,
768
- invalid,
769
- error,
770
- hint,
771
- "aria-label": ariaLabel,
772
- // Off `rest` and onto the <input>, which is the combobox a reader meets: `Field`'s
773
- // render-prop spreads `{ id, aria-describedby, aria-invalid, aria-required }`, and
774
- // on the wrapper div the hint and required state described nothing.
775
- "aria-describedby": ariaDescribedBy,
776
- "aria-invalid": ariaInvalid,
777
- "aria-required": ariaRequired,
778
- ...rest
779
- }: InlineEntityComboboxProps<V, C>) {
893
+ export function InlineEntityCombobox<V extends string | number, C extends ComboClearValue = null>(
894
+ props: InlineEntityComboboxProps<V, C>,
895
+ ) {
896
+ const {
897
+ value: rawValue,
898
+ onChange,
899
+ clearValue = null as C,
900
+ options,
901
+ label,
902
+ id,
903
+ placeholder,
904
+ className,
905
+ disabled,
906
+ autoFocus,
907
+ searchPlaceholder,
908
+ emptyLabel,
909
+ closeLabel,
910
+ clearable,
911
+ clearLabel,
912
+ disabledReason,
913
+ commit,
914
+ onCreate,
915
+ createLabel,
916
+ createEmptyLabel,
917
+ createCommit,
918
+ invalid,
919
+ error,
920
+ hint,
921
+ "aria-label": ariaLabel,
922
+ // Off `rest` and onto the <input>, which is the combobox a reader meets: `Field`'s
923
+ // render-prop spreads `{ id, aria-describedby, aria-invalid, aria-required }`, and
924
+ // on the wrapper div the hint and required state described nothing.
925
+ "aria-describedby": ariaDescribedBy,
926
+ "aria-invalid": ariaInvalid,
927
+ "aria-required": ariaRequired,
928
+ ...rest
929
+ } = props;
780
930
  // The clear value reads as "nothing selected", whichever one the caller picked —
781
931
  // so from here down `value` is the id or `null`, as it always was.
782
932
  const value: V | null = rawValue == null || rawValue === clearValue ? null : (rawValue as V);
@@ -812,7 +962,21 @@ export function InlineEntityCombobox<V extends string | number, C extends ComboC
812
962
  search: searchPlaceholder,
813
963
  noResults: emptyLabel,
814
964
  clear: clearLabel,
965
+ create: createLabel,
815
966
  });
967
+ // The lock (see `lockedKeyDown` above). A lock arriving mid-edit closes the list and
968
+ // drops the loose text, adjusted while rendering: nothing typed before it may be
969
+ // judged by `reconcile` after it.
970
+ const lock = useLockReason(commit, disabledReason);
971
+ const locked = lock.locked;
972
+ const inert = locked || Boolean(disabled);
973
+ if (locked && (open || text !== null)) {
974
+ setOpen(false);
975
+ setText(null);
976
+ }
977
+ // The create row's own lock (`createCommit`): the list stays live, the row does not.
978
+ const createReason = useCommitReason(createCommit, undefined);
979
+ const createLocked = hasMessage(createReason);
816
980
 
817
981
  const selected = useMemo(
818
982
  () => (value == null ? null : (options.find((o) => o.value === value) ?? null)),
@@ -821,7 +985,7 @@ export function InlineEntityCombobox<V extends string | number, C extends ComboC
821
985
  const shown = text ?? selected?.label ?? "";
822
986
  // Nothing selected has nothing to clear, and the chevron comes back — the field
823
987
  // keeps exactly one trailing control, so the "×" never crowds the value it sits on.
824
- const showClear = Boolean(clearable && value != null && !disabled);
988
+ const showClear = Boolean(clearable && value != null && !inert);
825
989
 
826
990
  // Focusing select-alls the current label; filtering only kicks in once the
827
991
  // text actually differs from it, so an already-filled field still opens on
@@ -855,11 +1019,35 @@ export function InlineEntityCombobox<V extends string | number, C extends ComboC
855
1019
  return [...blocks.values()].flat();
856
1020
  }, [options, query]);
857
1021
 
1022
+ // The create row (`onCreate`), on the query as typed — not lowercased: it becomes a
1023
+ // name. Compared against EVERY option, not `matches`: an exact hit anywhere is a
1024
+ // record that exists, disabled or not. Restated from `text` rather than derived from
1025
+ // `typedQuery`: this value is handed to the caller's `onCreate`, and the React
1026
+ // Compiler cannot then keep `matches` memoised on anything it was derived from.
1027
+ const createQuery = isPhone
1028
+ ? sheetQuery.trim()
1029
+ : text !== null && text !== (selected?.label ?? "")
1030
+ ? text.trim()
1031
+ : "";
1032
+ const showCreate = offersCreate(
1033
+ onCreate,
1034
+ createQuery,
1035
+ options.map((o) => o.label),
1036
+ createEmptyLabel,
1037
+ );
1038
+ const createText = createQuery ? labels.create(createQuery) : createEmptyLabel;
1039
+ // Every row the keyboard can land on: the options, then the create row — passed over
1040
+ // like a disabled option while a write lock holds it.
1041
+ const rows: readonly { disabled?: boolean }[] = showCreate
1042
+ ? [...matches, { disabled: createLocked }]
1043
+ : matches;
1044
+ const createIndex = matches.length;
1045
+
858
1046
  // Pointer-device only: the phone's rows live in a {@link PickerSheet} whose own
859
1047
  // search box holds focus, so the field behind it must not claim to be pointing at
860
1048
  // one of them.
861
1049
  // A disabled row is never the keyboard's, even if the list changed under it.
862
- const activeId = !isPhone && isOptionEnabled(matches[active]) ? optionId(active) : undefined;
1050
+ const activeId = !isPhone && isOptionEnabled(rows[active]) ? optionId(active) : undefined;
863
1051
  useActiveOptionScroll(activeId);
864
1052
 
865
1053
  const close = () => {
@@ -867,9 +1055,10 @@ export function InlineEntityCombobox<V extends string | number, C extends ComboC
867
1055
  setActive(-1);
868
1056
  setSheetQuery("");
869
1057
  };
870
- const commit = (o: ComboOption<V>) => {
871
- // A `disabled` option is listed, never taken — by any path.
872
- if (o.disabled) return;
1058
+ const take = (o: ComboOption<V>) => {
1059
+ // A `disabled` option is listed, never taken — by any path; nor is anything while
1060
+ // the field is locked.
1061
+ if (o.disabled || locked) return;
873
1062
  if (o.value !== value) onChange(o.value);
874
1063
  setText(null);
875
1064
  close();
@@ -884,8 +1073,15 @@ export function InlineEntityCombobox<V extends string | number, C extends ComboC
884
1073
  * used, then tabbing away, silently discarded it, and the more categories you used
885
1074
  * the more of them stopped working. Two rows naming the same id are not an ambiguity;
886
1075
  * two ids sharing a label are. */
1076
+ const create = () => {
1077
+ if (!onCreate || locked || createLocked) return;
1078
+ onCreate(createQuery);
1079
+ setText(null);
1080
+ close();
1081
+ };
887
1082
  const reconcile = () => {
888
- if (text !== null) {
1083
+ // Locked, loose text is dropped rather than judged: nothing reaches `onChange`.
1084
+ if (text !== null && !locked) {
889
1085
  const q = text.trim();
890
1086
  if (!q) {
891
1087
  if (value != null) onChange(clearValue);
@@ -898,11 +1094,36 @@ export function InlineEntityCombobox<V extends string | number, C extends ComboC
898
1094
  const ids = new Set(hits.map((h) => h.value));
899
1095
  if (ids.size === 1 && hits[0].value !== value) onChange(hits[0].value);
900
1096
  }
901
- setText(null);
902
1097
  }
1098
+ setText(null);
903
1099
  close();
904
1100
  };
905
1101
 
1102
+ // The create row's inside, one for both shells: a "+" (it is an action, not a record),
1103
+ // the words, and — while a write lock holds it — the lock's reason as a second line.
1104
+ const createRowContent = (
1105
+ <>
1106
+ <Plus aria-hidden className="size-4 shrink-0" />
1107
+ <span className="min-w-0 flex-1">
1108
+ <span className="block truncate">{createText}</span>
1109
+ {createLocked && (
1110
+ <span className="block truncate text-xs font-normal text-[var(--text-placeholder)]">
1111
+ {createReason}
1112
+ </span>
1113
+ )}
1114
+ </span>
1115
+ </>
1116
+ );
1117
+ // While locked the field sits in the reason's Tooltip — see Combobox.
1118
+ const withLock = (box: ReactNode) =>
1119
+ locked ? (
1120
+ <LockedReason lock={lock} className="block">
1121
+ {box}
1122
+ </LockedReason>
1123
+ ) : (
1124
+ box
1125
+ );
1126
+
906
1127
  return (
907
1128
  // `rest` dresses the outer box — a `data-tour` anchor, a test id. Not the NAME,
908
1129
  // description, invalid or required state: those belong on the <input> below,
@@ -911,152 +1132,162 @@ export function InlineEntityCombobox<V extends string | number, C extends ComboC
911
1132
  <div {...rest} ref={wrapperRef} className={cn("relative", className)}>
912
1133
  {/* A real <label for> — see {@link Combobox}; with a "?", in a row after the field. */}
913
1134
  {label !== undefined && hintParts.labelHint === undefined && (
914
- <ComboboxFieldLabel htmlFor={fieldId} className={disabled ? "opacity-50" : undefined}>
1135
+ <ComboboxFieldLabel htmlFor={fieldId} className={inert ? "opacity-50" : undefined}>
915
1136
  {label}
916
1137
  </ComboboxFieldLabel>
917
1138
  )}
918
- <EndHintRow hint={label === undefined ? hintParts.labelHint : undefined}>
919
- {/* Inner wrapper for chevron centering — same reasoning as Combobox above.
920
- It is also what the portalled list anchors to. */}
921
- {/* Dimmed as a whole when disabled, the way EntityCombobox dims its trigger.
922
- FIELD_BASE's grey alone left a disabled picker looking like a filled-in
923
- one beside the pickers that do dim (the label is not the input's `peer`,
924
- so it is dimmed by hand above). */}
925
- <div ref={fieldRef} className={cn("relative", disabled && "cursor-not-allowed opacity-50")}>
926
- <input
927
- id={fieldId}
928
- value={shown}
929
- placeholder={placeholder}
930
- // The caller's name, over the <label for> above. Just the label, never
931
- // "label: value" the way a trigger button has to compose it: an input
932
- // already exposes its value separately.
933
- aria-label={ariaLabel}
934
- role="combobox"
935
- aria-expanded={open}
936
- // Required by the role, and the half that was missing: the field said it
937
- // was expanded and never said what it had expanded (ESLint's
938
- // `role-has-required-aria-props`, the audit's §a11y).
939
- aria-controls={listboxId}
940
- aria-activedescendant={activeId}
941
- aria-autocomplete="list"
942
- aria-invalid={field.isInvalid || undefined}
943
- aria-describedby={field.describedBy}
944
- aria-required={ariaRequired}
945
- autoComplete="off"
946
- disabled={disabled}
947
- // eslint-disable-next-line jsx-a11y/no-autofocus -- a documented prop the caller opts into (off by default); the field never takes focus on its own.
948
- autoFocus={autoFocus}
949
- // `inputMode="none"` rather than readOnly, for the same reason Combobox
950
- // above gives: the sheet carries the keyboard, and a readOnly field would
951
- // take FIELD_BASE's settled look on a field that is perfectly editable.
952
- inputMode={isPhone ? "none" : undefined}
953
- onMouseDown={primaryOnly.onMouseDown}
954
- onFocus={(e) => {
955
- // See {@link usePrimaryPressOnly}: a back/forward button lands here on
956
- // its way to navigating, and neither the list nor the select-all is
957
- // anything it asked for (live #309 rework).
958
- if (primaryOnly.fromAuxButton()) return;
959
- setText(shown);
960
- e.currentTarget.select();
961
- setOpen(true);
962
- // The sheet has its own input; the field behind it must not also pull up
963
- // the keyboard and scroll the page under the dialog.
964
- if (isPhone) sheetInputRef.current?.focus();
965
- }}
966
- onBlur={() => {
967
- // On a phone the blur is the SHEET taking focus, not the user leaving the
968
- // field — reconciling there would close the sheet the instant it opened.
969
- if (!isPhone) reconcile();
970
- }}
971
- onChange={(e) => {
972
- setText(e.target.value);
973
- setOpen(true);
974
- setActive(-1);
975
- }}
976
- onKeyDown={(e) => {
977
- // Disabled rows are passed over; Up from "nothing highlighted" lands on
978
- // the first takeable row, as it always landed on row 0.
979
- if (e.key === "ArrowDown") {
980
- e.preventDefault();
1139
+ <EndHintRow {...endHintRowProps("hint" in props, label !== undefined, hintParts.labelHint)}>
1140
+ {withLock(
1141
+ /* Inner wrapper for chevron centering — same reasoning as Combobox above.
1142
+ It is also what the portalled list anchors to.
1143
+ Dimmed as a whole when disabled (or locked), the way EntityCombobox dims its
1144
+ trigger. FIELD_BASE's grey alone left a disabled picker looking like a
1145
+ filled-in one beside the pickers that do dim (the label is not the input's
1146
+ `peer`, so it is dimmed by hand above). */
1147
+ <div ref={fieldRef} className={cn("relative", inert && "cursor-not-allowed opacity-50")}>
1148
+ <input
1149
+ id={fieldId}
1150
+ value={shown}
1151
+ placeholder={placeholder}
1152
+ // The caller's name, over the <label for> above. Just the label, never
1153
+ // "label: value" the way a trigger button has to compose it: an input
1154
+ // already exposes its value separately.
1155
+ aria-label={ariaLabel}
1156
+ role="combobox"
1157
+ aria-expanded={open}
1158
+ // Required by the role, and the half that was missing: the field said it
1159
+ // was expanded and never said what it had expanded (ESLint's
1160
+ // `role-has-required-aria-props`, the audit's §a11y).
1161
+ aria-controls={listboxId}
1162
+ aria-activedescendant={activeId}
1163
+ aria-autocomplete="list"
1164
+ aria-invalid={field.isInvalid || undefined}
1165
+ aria-describedby={mergeDescribedBy(field.describedBy, locked && lock.reasonId)}
1166
+ aria-required={ariaRequired}
1167
+ autoComplete="off"
1168
+ // Locked: focusable, `readOnly`, `aria-disabled` — see `lockedKeyDown`.
1169
+ disabled={locked ? undefined : disabled}
1170
+ readOnly={locked || undefined}
1171
+ aria-disabled={locked || undefined}
1172
+ // eslint-disable-next-line jsx-a11y/no-autofocus -- a documented prop the caller opts into (off by default); the field never takes focus on its own.
1173
+ autoFocus={autoFocus}
1174
+ // `inputMode="none"` rather than readOnly, for the same reason Combobox
1175
+ // above gives: the sheet carries the keyboard, and a readOnly field would
1176
+ // take FIELD_BASE's settled look on a field that is perfectly editable.
1177
+ inputMode={isPhone ? "none" : undefined}
1178
+ onMouseDown={primaryOnly.onMouseDown}
1179
+ onFocus={(e) => {
1180
+ // See {@link usePrimaryPressOnly}: a back/forward button lands here on
1181
+ // its way to navigating, and neither the list nor the select-all is
1182
+ // anything it asked for (live #309 rework). A locked field takes focus to
1183
+ // say why, and opens nothing.
1184
+ if (primaryOnly.fromAuxButton() || locked) return;
1185
+ setText(shown);
1186
+ e.currentTarget.select();
981
1187
  setOpen(true);
982
- setActive((i) => stepEnabled(matches, i, 1));
983
- } else if (e.key === "ArrowUp") {
984
- e.preventDefault();
985
- setActive((i) => (i < 0 ? stepEnabled(matches, -1, 1) : stepEnabled(matches, i, -1)));
986
- } else if (e.key === "Enter") {
987
- if (open && isOptionEnabled(matches[active])) {
1188
+ // The sheet has its own input; the field behind it must not also pull up
1189
+ // the keyboard and scroll the page under the dialog.
1190
+ if (isPhone) sheetInputRef.current?.focus();
1191
+ }}
1192
+ onBlur={() => {
1193
+ // On a phone the blur is the SHEET taking focus, not the user leaving the
1194
+ // field — reconciling there would close the sheet the instant it opened.
1195
+ if (!isPhone) reconcile();
1196
+ }}
1197
+ onChange={(e) => {
1198
+ if (locked) return;
1199
+ setText(e.target.value);
1200
+ setOpen(true);
1201
+ setActive(-1);
1202
+ }}
1203
+ onKeyDown={(e) => {
1204
+ if (locked) return lockedKeyDown(e);
1205
+ // Disabled rows are passed over; Up from "nothing highlighted" lands on
1206
+ // the first takeable row, as it always landed on row 0. The create row is
1207
+ // the last row the arrows reach.
1208
+ if (e.key === "ArrowDown") {
988
1209
  e.preventDefault();
989
- commit(matches[active]);
990
- } else {
1210
+ setOpen(true);
1211
+ setActive((i) => stepEnabled(rows, i, 1));
1212
+ } else if (e.key === "ArrowUp") {
1213
+ e.preventDefault();
1214
+ setActive((i) => (i < 0 ? stepEnabled(rows, -1, 1) : stepEnabled(rows, i, -1)));
1215
+ } else if (e.key === "Enter") {
1216
+ if (open && isOptionEnabled(rows[active])) {
1217
+ e.preventDefault();
1218
+ if (active === createIndex && showCreate) create();
1219
+ else take(matches[active]);
1220
+ } else {
1221
+ reconcile();
1222
+ }
1223
+ } else if (e.key === "Escape") {
1224
+ setText(null);
1225
+ close();
1226
+ } else if (e.key === "Tab") {
1227
+ // Focus is in THIS input and stays there, so the browser's own Tab is
1228
+ // left alone; all that is needed is that the list stop covering what
1229
+ // the user is tabbing to. `reconcile` rather than `close`, because
1230
+ // leaving the field is exactly when loose text has to be judged.
991
1231
  reconcile();
992
1232
  }
993
- } else if (e.key === "Escape") {
994
- setText(null);
995
- close();
996
- } else if (e.key === "Tab") {
997
- // Focus is in THIS input and stays there, so the browser's own Tab is
998
- // left alone; all that is needed is that the list stop covering what
999
- // the user is tabbing to. `reconcile` rather than `close`, because
1000
- // leaving the field is exactly when loose text has to be judged.
1001
- reconcile();
1002
- }
1003
- // Home/End stay with the caret — see the note in {@link Combobox}: this
1004
- // field is editable, and its text is what `reconcile` judges.
1005
- }}
1006
- className={cn(
1007
- FIELD_BASE,
1008
- label !== undefined && FIELD_FLOATING_PAD,
1009
- "pe-9",
1010
- field.isInvalid && FIELD_INVALID,
1011
- )}
1012
- />
1013
- {showClear ? (
1014
- <button
1015
- type="button"
1016
- // Out of the tab order, like the clear on `EntityCombobox`: the keyboard
1017
- // already clears this field by selecting its text and deleting, and a
1018
- // second stop between every picker and the next field is a worse trade
1019
- // than the one gesture it saves.
1020
- tabIndex={-1}
1021
- aria-label={labels.clear}
1022
- // preventDefault, exactly as the chevron does: without it the press
1023
- // focuses the input, which on a phone opens the sheet over the field the
1024
- // press was clearing.
1025
- onMouseDown={(e) => e.preventDefault()}
1026
- onClick={() => {
1027
- setText(null);
1028
- close();
1029
- onChange(clearValue);
1233
+ // Home/End stay with the caret — see the note in {@link Combobox}: this
1234
+ // field is editable, and its text is what `reconcile` judges.
1030
1235
  }}
1031
1236
  className={cn(
1032
- "absolute end-2 top-1/2 -translate-y-1/2 rounded p-0.5 text-[var(--text-placeholder)]",
1033
- "hover:text-[var(--text-secondary)]",
1034
- )}
1035
- >
1036
- <X aria-hidden className="size-4" />
1037
- </button>
1038
- ) : (
1039
- <ChevronDown
1040
- aria-hidden
1041
- onMouseDown={(e) => {
1042
- // Toggle on the chevron without stealing focus from the input — and
1043
- // not at all on a disabled field, which the input's own `disabled`
1044
- // does not stop from here.
1045
- e.preventDefault();
1046
- if (!disabled) setOpen((o) => !o);
1047
- }}
1048
- className={cn(
1049
- "absolute end-2.5 top-1/2 size-4 -translate-y-1/2 text-[var(--text-placeholder)]",
1050
- // The box above does the dimming; dimming here too would halve it again.
1051
- !disabled && "cursor-pointer",
1237
+ FIELD_BASE,
1238
+ label !== undefined && FIELD_FLOATING_PAD,
1239
+ "pe-9",
1240
+ field.isInvalid && FIELD_INVALID,
1052
1241
  )}
1053
1242
  />
1054
- )}
1055
- </div>
1243
+ {showClear ? (
1244
+ <button
1245
+ type="button"
1246
+ // Out of the tab order, like the clear on `EntityCombobox`: the keyboard
1247
+ // already clears this field by selecting its text and deleting, and a
1248
+ // second stop between every picker and the next field is a worse trade
1249
+ // than the one gesture it saves.
1250
+ tabIndex={-1}
1251
+ aria-label={labels.clear}
1252
+ // preventDefault, exactly as the chevron does: without it the press
1253
+ // focuses the input, which on a phone opens the sheet over the field the
1254
+ // press was clearing.
1255
+ onMouseDown={(e) => e.preventDefault()}
1256
+ onClick={() => {
1257
+ setText(null);
1258
+ close();
1259
+ if (!locked) onChange(clearValue);
1260
+ }}
1261
+ className={cn(
1262
+ "absolute end-2 top-1/2 -translate-y-1/2 rounded p-0.5 text-[var(--text-placeholder)]",
1263
+ "hover:text-[var(--text-secondary)]",
1264
+ )}
1265
+ >
1266
+ <X aria-hidden className="size-4" />
1267
+ </button>
1268
+ ) : (
1269
+ <ChevronDown
1270
+ aria-hidden
1271
+ onMouseDown={(e) => {
1272
+ // Toggle on the chevron without stealing focus from the input — and
1273
+ // not at all on a disabled or locked field, which the input's own
1274
+ // `disabled`/`readOnly` does not stop from here.
1275
+ e.preventDefault();
1276
+ if (!inert) setOpen((o) => !o);
1277
+ }}
1278
+ className={cn(
1279
+ "absolute end-2.5 top-1/2 size-4 -translate-y-1/2 text-[var(--text-placeholder)]",
1280
+ // The box above does the dimming; dimming here too would halve it again.
1281
+ !inert && "cursor-pointer",
1282
+ )}
1283
+ />
1284
+ )}
1285
+ </div>,
1286
+ )}
1056
1287
  </EndHintRow>
1057
1288
  {label !== undefined && hintParts.labelHint !== undefined && (
1058
1289
  <StaticLabelRow hint={hintParts.labelHint}>
1059
- <ComboboxFieldLabel htmlFor={fieldId} className={cn(LABEL_IN_ROW, disabled && "opacity-50")}>
1290
+ <ComboboxFieldLabel htmlFor={fieldId} className={cn(LABEL_IN_ROW, inert && "opacity-50")}>
1060
1291
  {label}
1061
1292
  </ComboboxFieldLabel>
1062
1293
  </StaticLabelRow>
@@ -1065,7 +1296,7 @@ export function InlineEntityCombobox<V extends string | number, C extends ComboC
1065
1296
  {field.errorEl}
1066
1297
  {isPhone && (
1067
1298
  <PickerSheet
1068
- open={open && !disabled}
1299
+ open={open && !inert}
1069
1300
  // Closing without choosing keeps the value: `text` was never emptied, so
1070
1301
  // reconcile has nothing to undo — it just puts the label back.
1071
1302
  onClose={reconcile}
@@ -1099,7 +1330,7 @@ export function InlineEntityCombobox<V extends string | number, C extends ComboC
1099
1330
  role="option"
1100
1331
  aria-selected={o.value === value}
1101
1332
  aria-disabled={o.disabled || undefined}
1102
- onClick={() => commit(o)}
1333
+ onClick={() => take(o)}
1103
1334
  className={cn(
1104
1335
  SHEET_ROW_CLASS,
1105
1336
  o.value === value && "font-medium",
@@ -1111,13 +1342,34 @@ export function InlineEntityCombobox<V extends string | number, C extends ComboC
1111
1342
  </li>
1112
1343
  </Fragment>
1113
1344
  ))}
1114
- {matches.length === 0 && (
1345
+ {showCreate && (
1346
+ <li role="presentation">
1347
+ <button
1348
+ type="button"
1349
+ role="option"
1350
+ // An action, never chosen — see `onCreate`.
1351
+ aria-selected={false}
1352
+ aria-disabled={createLocked || undefined}
1353
+ onClick={create}
1354
+ className={cn(
1355
+ SHEET_ROW_CLASS,
1356
+ CREATE_ROW_CLASS,
1357
+ createLocked && DISABLED_ROW_CLASS,
1358
+ )}
1359
+ >
1360
+ {createRowContent}
1361
+ </button>
1362
+ </li>
1363
+ )}
1364
+ {/* "Nothing matched" only when there is nothing to do either: with a create
1365
+ row the list is not empty, it is offering to fill itself. */}
1366
+ {matches.length === 0 && !showCreate && (
1115
1367
  <li className="px-4 py-3 text-sm text-[var(--text-muted)]">{labels.noResults}</li>
1116
1368
  )}
1117
1369
  </ul>
1118
1370
  </PickerSheet>
1119
1371
  )}
1120
- {!isPhone && open && !disabled && matches.length > 0 && (
1372
+ {!isPhone && open && !inert && (matches.length > 0 || showCreate) && (
1121
1373
  <SuggestionList id={listboxId} anchorRef={fieldRef} panelRef={panelRef}>
1122
1374
  {matches.map((o, i) => (
1123
1375
  // A group heading is emitted at each group boundary rather than repeating
@@ -1151,7 +1403,7 @@ export function InlineEntityCombobox<V extends string | number, C extends ComboC
1151
1403
  // list before the selection registers. Prevented on a disabled
1152
1404
  // row too, so pressing one leaves the field focused and open.
1153
1405
  e.preventDefault();
1154
- commit(o);
1406
+ take(o);
1155
1407
  }}
1156
1408
  onMouseEnter={() => {
1157
1409
  if (!o.disabled) setActive(i);
@@ -1175,6 +1427,36 @@ export function InlineEntityCombobox<V extends string | number, C extends ComboC
1175
1427
  </li>
1176
1428
  </Fragment>
1177
1429
  ))}
1430
+ {showCreate && (
1431
+ <li role="presentation">
1432
+ <button
1433
+ type="button"
1434
+ id={optionId(createIndex)}
1435
+ role="option"
1436
+ // An action, never chosen; whether the keyboard is ON it is the field's
1437
+ // `aria-activedescendant`'s to say.
1438
+ aria-selected={false}
1439
+ aria-disabled={createLocked || undefined}
1440
+ tabIndex={-1}
1441
+ onMouseDown={(e) => {
1442
+ // mousedown, like the rows above: the input's blur would otherwise
1443
+ // reconcile and close the list before the click landed.
1444
+ e.preventDefault();
1445
+ create();
1446
+ }}
1447
+ onMouseEnter={() => {
1448
+ if (!createLocked) setActive(createIndex);
1449
+ }}
1450
+ className={cn(
1451
+ rowClass(active === createIndex && !createLocked),
1452
+ CREATE_ROW_CLASS,
1453
+ createLocked && DISABLED_ROW_CLASS,
1454
+ )}
1455
+ >
1456
+ {createRowContent}
1457
+ </button>
1458
+ </li>
1459
+ )}
1178
1460
  </SuggestionList>
1179
1461
  )}
1180
1462
  </div>