@eifi1/ui-kit 0.21.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.
- package/README.md +42 -25
- package/dist/chart.d.ts +19 -14
- package/dist/components/account-chips.d.ts +10 -3
- package/dist/components/account-chips.js +5 -2
- package/dist/components/account-chips.js.map +1 -1
- package/dist/components/account-settings.d.ts +33 -2
- package/dist/components/account-settings.js +43 -21
- package/dist/components/account-settings.js.map +1 -1
- package/dist/components/amount-input.d.ts +53 -14
- package/dist/components/amount-input.js +17 -28
- package/dist/components/amount-input.js.map +1 -1
- package/dist/components/autocomplete.d.ts +29 -0
- package/dist/components/autocomplete.js +134 -104
- package/dist/components/autocomplete.js.map +1 -1
- package/dist/components/button-group.d.ts +19 -14
- package/dist/components/calculator.d.ts +19 -14
- package/dist/components/checkbox-group.d.ts +104 -0
- package/dist/components/checkbox-group.js +111 -0
- package/dist/components/checkbox-group.js.map +1 -0
- package/dist/components/checkbox.d.ts +19 -0
- package/dist/components/checkbox.js +30 -7
- package/dist/components/checkbox.js.map +1 -1
- package/dist/components/chip.d.ts +18 -0
- package/dist/components/chip.js +47 -10
- package/dist/components/chip.js.map +1 -1
- package/dist/components/column-mapper.d.ts +182 -0
- package/dist/components/column-mapper.js +375 -0
- package/dist/components/column-mapper.js.map +1 -0
- package/dist/components/combobox-core.d.ts +39 -2
- package/dist/components/combobox-core.js +29 -6
- package/dist/components/combobox-core.js.map +1 -1
- package/dist/components/combobox.d.ts +91 -2
- package/dist/components/combobox.js +454 -308
- package/dist/components/combobox.js.map +1 -1
- package/dist/components/confirm-dialog.d.ts +69 -161
- package/dist/components/confirm-dialog.js +7 -8
- package/dist/components/confirm-dialog.js.map +1 -1
- package/dist/components/copy-button.d.ts +16 -11
- package/dist/components/country-select.d.ts +167 -0
- package/dist/components/country-select.js +293 -0
- package/dist/components/country-select.js.map +1 -0
- package/dist/components/currency-select.d.ts +17 -1
- package/dist/components/currency-select.js +56 -23
- package/dist/components/currency-select.js.map +1 -1
- package/dist/components/danger-confirm.d.ts +69 -166
- package/dist/components/danger-confirm.js +144 -50
- package/dist/components/danger-confirm.js.map +1 -1
- package/dist/components/data-table-cells.d.ts +1 -2
- package/dist/components/data-table-filter-popover.d.ts +1 -2
- package/dist/components/data-table-filters.d.ts +1 -2
- package/dist/components/data-table-labels.d.ts +4 -97
- package/dist/components/data-table-labels.js +9 -1
- package/dist/components/data-table-labels.js.map +1 -1
- package/dist/components/data-table-pagination.d.ts +3 -1
- package/dist/components/data-table.d.ts +1 -2
- package/dist/components/data-table.js +98 -3
- package/dist/components/data-table.js.map +1 -1
- package/dist/components/date-picker.d.ts +66 -5
- package/dist/components/date-picker.js +378 -66
- package/dist/components/date-picker.js.map +1 -1
- package/dist/components/entity-combobox.d.ts +42 -1
- package/dist/components/entity-combobox.js +154 -113
- package/dist/components/entity-combobox.js.map +1 -1
- package/dist/components/facing-pair.d.ts +19 -14
- package/dist/components/field-parts.d.ts +224 -0
- package/dist/components/field-parts.js +156 -0
- package/dist/components/field-parts.js.map +1 -0
- package/dist/components/field-strip.d.ts +105 -0
- package/dist/components/field-strip.js +46 -0
- package/dist/components/field-strip.js.map +1 -0
- package/dist/components/file-button.d.ts +19 -14
- package/dist/components/file-button.js +13 -3
- package/dist/components/file-button.js.map +1 -1
- package/dist/components/file-dropzone.d.ts +41 -15
- package/dist/components/file-dropzone.js +57 -34
- package/dist/components/file-dropzone.js.map +1 -1
- package/dist/components/form-actions.d.ts +18 -13
- package/dist/components/form-actions.js +69 -5
- package/dist/components/form-actions.js.map +1 -1
- package/dist/components/iban-input.d.ts +69 -0
- package/dist/components/iban-input.js +125 -0
- package/dist/components/iban-input.js.map +1 -0
- package/dist/components/icon-picker.d.ts +21 -2
- package/dist/components/icon-picker.js +19 -4
- package/dist/components/icon-picker.js.map +1 -1
- package/dist/components/inline-edit-field.d.ts +167 -0
- package/dist/components/inline-edit-field.js +293 -0
- package/dist/components/inline-edit-field.js.map +1 -0
- package/dist/components/language-select.d.ts +130 -0
- package/dist/components/language-select.js +18 -0
- package/dist/components/language-select.js.map +1 -0
- package/dist/components/line-items.d.ts +25 -3
- package/dist/components/line-items.js +55 -46
- package/dist/components/line-items.js.map +1 -1
- package/dist/components/list.d.ts +25 -0
- package/dist/components/list.js +16 -5
- package/dist/components/list.js.map +1 -1
- package/dist/components/money-field.d.ts +32 -14
- package/dist/components/money-field.js.map +1 -1
- package/dist/components/month-picker.d.ts +52 -4
- package/dist/components/month-picker.js +291 -86
- package/dist/components/month-picker.js.map +1 -1
- package/dist/components/multi-entity-combobox.d.ts +26 -1
- package/dist/components/multi-entity-combobox.js +143 -102
- package/dist/components/multi-entity-combobox.js.map +1 -1
- package/dist/components/multi-select.d.ts +8 -1
- package/dist/components/multi-select.js +9 -4
- package/dist/components/multi-select.js.map +1 -1
- package/dist/components/number-field.d.ts +34 -19
- package/dist/components/number-field.js +6 -20
- package/dist/components/number-field.js.map +1 -1
- package/dist/components/number-input.d.ts +79 -19
- package/dist/components/number-input.js +90 -38
- package/dist/components/number-input.js.map +1 -1
- package/dist/components/numpad-sheet.d.ts +19 -14
- package/dist/components/one-time-code-input.d.ts +100 -0
- package/dist/components/one-time-code-input.js +137 -0
- package/dist/components/one-time-code-input.js.map +1 -0
- package/dist/components/phone-input.d.ts +69 -0
- package/dist/components/phone-input.js +171 -0
- package/dist/components/phone-input.js.map +1 -0
- package/dist/components/reauth-dialog.d.ts +2 -2
- package/dist/components/reauth-dialog.js +6 -8
- package/dist/components/reauth-dialog.js.map +1 -1
- package/dist/components/series-chart.d.ts +19 -14
- package/dist/components/settings-fields.d.ts +19 -14
- package/dist/components/share-card.d.ts +16 -11
- package/dist/components/sign-chip.d.ts +66 -0
- package/dist/components/sign-chip.js +39 -0
- package/dist/components/sign-chip.js.map +1 -0
- package/dist/components/swatch-picker.d.ts +43 -2
- package/dist/components/swatch-picker.js +80 -32
- package/dist/components/swatch-picker.js.map +1 -1
- package/dist/components/switch.d.ts +19 -0
- package/dist/components/switch.js +24 -6
- package/dist/components/switch.js.map +1 -1
- package/dist/components/text-link.d.ts +18 -13
- package/dist/components/tile-radio.d.ts +88 -13
- package/dist/components/tile-radio.js +28 -11
- package/dist/components/tile-radio.js.map +1 -1
- package/dist/components/time-input.d.ts +24 -15
- package/dist/components/time-input.js.map +1 -1
- package/dist/components/toggle-group.d.ts +47 -1
- package/dist/components/toggle-group.js +110 -69
- package/dist/components/toggle-group.js.map +1 -1
- package/dist/components/trigger-aria.d.ts +3 -0
- package/dist/components/trigger-aria.js +3 -1
- package/dist/components/trigger-aria.js.map +1 -1
- package/dist/components/ui.d.ts +16 -11
- package/dist/components/ui.js +284 -88
- package/dist/components/ui.js.map +1 -1
- package/dist/components/use-table-state.d.ts +1 -2
- package/dist/{data-table-3mi2R3so.d.ts → data-table-labels-B7OdnM0S.d.ts} +140 -3
- package/dist/data-table.d.ts +1 -2
- package/dist/data-table.js +2 -1
- package/dist/data-table.js.map +1 -1
- package/dist/feedback/feedback-attachment.d.ts +1 -1
- package/dist/feedback/feedback-attachment.js +348 -41
- package/dist/feedback/feedback-attachment.js.map +1 -1
- package/dist/feedback/feedback-dialog.d.ts +1 -1
- package/dist/feedback/feedback-dialog.js.map +1 -1
- package/dist/feedback/feedback-inbox.d.ts +3 -2
- package/dist/feedback/feedback-inbox.js.map +1 -1
- package/dist/feedback/feedback-thread.d.ts +68 -253
- package/dist/feedback/feedback-thread.js +46 -10
- package/dist/feedback/feedback-thread.js.map +1 -1
- package/dist/{kit-labels-D1J2_jyD.d.ts → feedback-BxeQVzwq.d.ts} +1206 -20
- package/dist/{feedback-attachment-WFiXJ8We.d.ts → feedback-attachment-fGAzZPf0.d.ts} +178 -11
- package/dist/feedback.d.ts +66 -2
- package/dist/hooks/use-file-drop.d.ts +19 -14
- package/dist/i18n/defaults.d.ts +19 -14
- package/dist/i18n/defaults.js +19 -2
- package/dist/i18n/defaults.js.map +1 -1
- package/dist/i18n/german.d.ts +19 -14
- package/dist/i18n/german.js +84 -5
- package/dist/i18n/german.js.map +1 -1
- package/dist/i18n/kit-labels.d.ts +15 -10
- package/dist/i18n/kit-labels.js +8 -2
- package/dist/i18n/kit-labels.js.map +1 -1
- package/dist/i18n/languages.d.ts +19 -14
- package/dist/i18n/locales/de-CH.d.ts +19 -14
- package/dist/i18n/locales/en.d.ts +19 -14
- package/dist/i18n/locales/en.js +16 -0
- package/dist/i18n/locales/en.js.map +1 -1
- package/dist/i18n/locales/es.d.ts +19 -14
- package/dist/i18n/locales/es.js +83 -5
- package/dist/i18n/locales/es.js.map +1 -1
- package/dist/i18n/locales/fr.d.ts +19 -14
- package/dist/i18n/locales/fr.js +82 -5
- package/dist/i18n/locales/fr.js.map +1 -1
- package/dist/i18n/locales/hu.d.ts +19 -14
- package/dist/i18n/locales/hu.js +85 -5
- package/dist/i18n/locales/hu.js.map +1 -1
- package/dist/i18n/locales/it.d.ts +19 -14
- package/dist/i18n/locales/it.js +84 -5
- package/dist/i18n/locales/it.js.map +1 -1
- package/dist/i18n/locales/zh.d.ts +19 -14
- package/dist/i18n/locales/zh.js +80 -5
- package/dist/i18n/locales/zh.js.map +1 -1
- package/dist/i18n/review.d.ts +19 -14
- package/dist/i18n/review.js +27 -1
- package/dist/i18n/review.js.map +1 -1
- package/dist/index.d.ts +21 -10
- package/dist/index.js +73 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/column-mapping.d.ts +81 -0
- package/dist/lib/column-mapping.js +108 -0
- package/dist/lib/column-mapping.js.map +1 -0
- package/dist/lib/countries.d.ts +43 -0
- package/dist/lib/countries.js +39 -0
- package/dist/lib/countries.js.map +1 -0
- package/dist/lib/decimal-marks.d.ts +46 -0
- package/dist/lib/decimal-marks.js +40 -0
- package/dist/lib/decimal-marks.js.map +1 -0
- package/dist/lib/iban.d.ts +98 -0
- package/dist/lib/iban.js +154 -0
- package/dist/lib/iban.js.map +1 -0
- package/dist/lib/isin.d.ts +30 -0
- package/dist/lib/isin.js +36 -0
- package/dist/lib/isin.js.map +1 -0
- package/dist/lib/phone.d.ts +69 -0
- package/dist/lib/phone.js +121 -0
- package/dist/lib/phone.js.map +1 -0
- package/dist/lib/table-text.d.ts +109 -1
- package/dist/lib/table-text.js +122 -1
- package/dist/lib/table-text.js.map +1 -1
- package/dist/rhf/fields.d.ts +233 -18
- package/dist/rhf/fields.js +456 -3
- package/dist/rhf/fields.js.map +1 -1
- package/dist/rhf/form.d.ts +19 -14
- package/dist/rhf.d.ts +22 -15
- package/dist/rhf.js.map +1 -1
- package/dist/shell/app-shell.d.ts +18 -13
- package/dist/shell/top-bar-brand.d.ts +19 -14
- package/dist/shell/topbar-action-menu.d.ts +36 -3
- package/dist/shell/topbar-action-menu.js +74 -33
- package/dist/shell/topbar-action-menu.js.map +1 -1
- package/dist/shell.d.ts +18 -13
- package/dist/table-text.d.ts +1 -1
- package/dist/tour/tour.js +20 -24
- package/dist/tour/tour.js.map +1 -1
- package/dist/wizard/stepper-nav.d.ts +49 -16
- package/dist/wizard/stepper-nav.js +4 -0
- package/dist/wizard/stepper-nav.js.map +1 -1
- package/dist/wizard.d.ts +19 -14
- package/package.json +1 -1
- package/src/components/account-chips.tsx +17 -3
- package/src/components/account-settings.tsx +92 -26
- package/src/components/amount-input.tsx +68 -56
- package/src/components/autocomplete.tsx +198 -114
- package/src/components/checkbox-group.tsx +229 -0
- package/src/components/checkbox.tsx +72 -8
- package/src/components/chip.tsx +80 -10
- package/src/components/column-mapper.tsx +666 -0
- package/src/components/combobox-core.tsx +82 -9
- package/src/components/combobox.tsx +661 -340
- package/src/components/confirm-dialog.tsx +12 -8
- package/src/components/country-select.tsx +556 -0
- package/src/components/currency-select.tsx +109 -33
- package/src/components/danger-confirm.tsx +429 -82
- package/src/components/data-table-labels.ts +16 -1
- package/src/components/data-table.tsx +175 -6
- package/src/components/date-picker.tsx +595 -71
- package/src/components/entity-combobox.tsx +235 -124
- package/src/components/field-parts.tsx +403 -0
- package/src/components/field-strip.tsx +149 -0
- package/src/components/file-button.tsx +36 -3
- package/src/components/file-dropzone.tsx +106 -38
- package/src/components/form-actions.tsx +147 -6
- package/src/components/iban-input.tsx +231 -0
- package/src/components/icon-picker.tsx +47 -6
- package/src/components/inline-edit-field.tsx +533 -0
- package/src/components/language-select.tsx +78 -0
- package/src/components/line-items.tsx +35 -2
- package/src/components/list.tsx +55 -6
- package/src/components/money-field.tsx +13 -0
- package/src/components/month-picker.tsx +400 -63
- package/src/components/multi-entity-combobox.tsx +207 -120
- package/src/components/multi-select.tsx +80 -58
- package/src/components/number-field.tsx +28 -46
- package/src/components/number-input.tsx +210 -43
- package/src/components/one-time-code-input.tsx +288 -0
- package/src/components/phone-input.tsx +299 -0
- package/src/components/reauth-dialog.tsx +17 -18
- package/src/components/sign-chip.tsx +103 -0
- package/src/components/swatch-picker.tsx +143 -31
- package/src/components/switch.tsx +58 -7
- package/src/components/tile-radio.tsx +145 -29
- package/src/components/time-input.tsx +8 -1
- package/src/components/toggle-group.tsx +206 -73
- package/src/components/trigger-aria.ts +5 -0
- package/src/components/ui.tsx +479 -138
- package/src/data-table.ts +2 -1
- package/src/feedback/feedback-attachment.tsx +597 -46
- package/src/feedback/feedback-dialog.tsx +9 -3
- package/src/feedback/feedback-inbox.tsx +3 -2
- package/src/feedback/feedback-thread.tsx +113 -9
- package/src/i18n/defaults.ts +18 -1
- package/src/i18n/german.ts +89 -0
- package/src/i18n/kit-labels.tsx +82 -2
- package/src/i18n/locales/en.ts +36 -4
- package/src/i18n/locales/es.ts +87 -0
- package/src/i18n/locales/fr.ts +87 -0
- package/src/i18n/locales/hu.ts +83 -0
- package/src/i18n/locales/it.ts +88 -0
- package/src/i18n/locales/zh.ts +76 -0
- package/src/i18n/review.ts +26 -0
- package/src/index.ts +71 -3
- package/src/lib/column-mapping.ts +234 -0
- package/src/lib/countries.ts +91 -0
- package/src/lib/decimal-marks.ts +99 -0
- package/src/lib/iban.ts +171 -0
- package/src/lib/isin.ts +62 -0
- package/src/lib/phone.ts +211 -0
- package/src/lib/table-text.ts +271 -0
- package/src/rhf/fields.tsx +860 -9
- package/src/rhf.ts +3 -1
- package/src/shell/topbar-action-menu.tsx +134 -38
- package/src/tour/tour.tsx +66 -28
- package/src/wizard/stepper-nav.tsx +35 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/combobox-core.tsx"],"sourcesContent":["import { Fragment, useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport type {\n ComponentPropsWithoutRef,\n Dispatch,\n KeyboardEvent as ReactKeyboardEvent,\n ReactNode,\n RefObject,\n SetStateAction,\n} from \"react\";\nimport { Check, Plus } from \"lucide-react\";\nimport { cn } from \"../lib/cn\";\nimport { CLIPS_ATTRIBUTE } from \"../lib/clipping\";\nimport { DropdownSearchHeader } from \"./dropdown\";\nimport { PickerSheet, SHEET_ROW_CLASS } from \"./picker-sheet\";\nimport { useMediaQuery } from \"../hooks/use-media-query\";\nimport { FLOATING_LABEL_STATIC, PHONE_QUERY, Spinner } from \"./ui\";\nimport { useAnchorDir } from \"./use-anchor-dir\";\nimport { type AnchorRect } from \"../hooks/use-anchored-rect\";\nimport { useAnchoredPanel, type AnchoredPanel } from \"../hooks/use-anchored-panel\";\nimport { useEscapeKey, useOutsideClick } from \"../hooks/use-dismiss\";\nimport { DEFAULT_COMBOBOX_LABELS, useKitLabels } from \"../i18n/kit-labels\";\nimport { hasMessage, mergeDescribedBy } from \"./choice-parts\";\n\n/**\n * What an entity picker hands `onChange` when it is cleared — `clearValue` on\n * {@link EntityCombobox} and {@link InlineEntityCombobox}. `null` by default.\n *\n * A closed set rather than any value, on purpose: every member is something no\n * option can be (an option's value is a `string | number`, and `\"\"` is never a real\n * id), so the picker can also READ it back — a field whose `value` is the clear\n * value shows as empty, with no clear button, exactly as `null` does. An arbitrary\n * sentinel could collide with an id and would make that read ambiguous.\n *\n * No `undefined`: a prop set to `undefined` is a prop not passed, so it would read as\n * the default and emit `null` — the one outcome the caller had asked not to get.\n */\nexport type ComboClearValue = null | \"\";\n\nexport interface ComboOption<V extends string | number> {\n value: V;\n label: string;\n sublabel?: string;\n icon?: ReactNode;\n /**\n * Section this option belongs to. Where a consumer renders it as a heading with the\n * members indented beneath — {@link InlineEntityCombobox} does — this is a genuine\n * grouping, not decoration: the name appears once per section rather than trailing\n * every row in small grey type, which is barely legible on a phone (feedback #136).\n * Searchable like `sublabel`.\n */\n group?: string;\n /**\n * Shown but not takeable: rendered dimmed with `aria-disabled`, passed over by the\n * arrow keys, and a click or Enter on it does nothing. For a row whose existence is\n * the information — a write-locked result, an account that is closed — where\n * leaving it out would read as \"there is no such thing\". Say WHY in `sublabel`: a\n * hover tooltip is the one explanation a phone cannot show.\n *\n * Honoured by {@link Autocomplete}, {@link InlineEntityCombobox} and the panel\n * pickers ({@link EntityCombobox}, {@link MultiEntityCombobox}); on those an already\n * chosen disabled option stays chosen — the row only refuses to be toggled.\n */\n disabled?: boolean;\n}\n\n/** A row the user may take — present and not {@link ComboOption.disabled}. */\nexport const isOptionEnabled = (o: { disabled?: boolean } | undefined): boolean =>\n o !== undefined && !o.disabled;\n\n/**\n * The next takeable row from `from`, stepping `dir` — what the arrow keys use so a\n * disabled row is passed over, as the APG allows. Stays on `from` at the end of the\n * list (the family's arrows clamp rather than wrap) and answers `-1` when `from` is\n * not a row and there is nothing to step to.\n */\nexport function stepEnabled(\n rows: readonly { disabled?: boolean }[],\n from: number,\n dir: 1 | -1,\n): number {\n for (let i = from + dir; i >= 0 && i < rows.length; i += dir) {\n if (!rows[i].disabled) return i;\n }\n return from >= 0 && from < rows.length ? from : -1;\n}\n\n/** `i` when that row is takeable, else the nearest takeable one after it, else\n * before it, else `-1`. For a highlight that starts on a fixed index (the panel\n * pickers open on row 0) and must never rest on a disabled row. */\nexport function settleEnabled(rows: readonly { disabled?: boolean }[], i: number): number {\n if (i < 0 || i >= rows.length) return -1;\n if (!rows[i].disabled) return i;\n const after = stepEnabled(rows, i, 1);\n if (after !== i) return after;\n const before = stepEnabled(rows, i, -1);\n return before !== i ? before : -1;\n}\n\n/** Classes a disabled row adds over its normal ones — dimmed, no hover, the\n * kit's soft-disabled look (`DangerConfirm`, `SignaturePad`). */\nexport const DISABLED_ROW_CLASS = \"cursor-not-allowed opacity-50 hover:bg-transparent\";\n\n/**\n * The family's floating label, as a real `<label for>` (lenkbank): the input is then\n * named the way {@link Input}'s is, so `getByLabelText` and any helper that walks\n * `<label htmlFor>` finds it. Same placement and type as {@link FieldLabel}, which\n * stays a `<span>` for the TRIGGER pickers — a `<button>` is labelable, but those\n * compose their own \"label: value\" name. `pointer-events-none` (from the class)\n * keeps a press on it landing on the field under it, as before.\n */\nexport function ComboboxFieldLabel({\n htmlFor,\n className,\n children,\n ...rest\n}: ComponentPropsWithoutRef<\"label\"> & { htmlFor: string }) {\n return (\n <label {...rest} htmlFor={htmlFor} className={cn(FLOATING_LABEL_STATIC, \"z-10\", className)}>\n {children}\n </label>\n );\n}\n\n/**\n * Where a combobox's rows come from, and how a query narrows them. Shared by the\n * trigger pickers ({@link useComboboxCore}) and the inline {@link Autocomplete}, so\n * the two cannot drift in what a failed lookup or a too-short query does.\n */\nexport interface OptionSourceOptions<V extends string | number> {\n /** Already-loaded options (client-side filtered unless `filter` is false), also\n * used to resolve labels. */\n options?: ComboOption<V>[];\n /** Async option source, debounced and race-safe; stale responses are ignored,\n * and a rejection is caught and reported as `failed`. */\n loadOptions?: (query: string) => Promise<ComboOption<V>[]>;\n /** External loading flag, OR-ed with the internal async state. */\n loading?: boolean;\n /**\n * Narrow `options` by the query (label/sublabel substring). Default `true`.\n *\n * `false` shows `options` exactly as given, in the given order — for a list the\n * caller has already searched and ranked on a server (Keksdose's geocoder), which a\n * second, client-side substring filter could only get wrong: a provider that\n * matches \"Bahnhofstr.\" to \"Bahnhofstrasse\" is right, and a label filter would\n * throw that row away.\n */\n filter?: boolean;\n /**\n * Below this many (trimmed) characters nothing is offered and `loadOptions` is not\n * called. Default `0` — the pickers list everything on open. Set it for a source\n * that is costly or rate-limited: one letter against a geocoder matches half a\n * continent, and a request per opened panel is a request nobody asked for.\n */\n minChars?: number;\n /** Quiet time after the last keystroke before `loadOptions` runs. Default 150 ms. */\n debounceMs?: number;\n}\n\nexport interface OptionSource<V extends string | number> {\n results: ComboOption<V>[];\n busy: boolean;\n /** The last lookup for this query REJECTED. The rows are emptied with it: results\n * from an earlier query under a failed one would read as the answer to it. */\n failed: boolean;\n /** The query is shorter than `minChars`, so nothing was asked. */\n tooShort: boolean;\n}\n\n/**\n * The rows half of a combobox: client-side filtering, or a debounced, race-safe\n * `loadOptions` with its loading and failure states.\n *\n * `active` gates the async side — a closed list asks nothing. Loading is DERIVED\n * (\"the settled answer is for a different query\") rather than flagged on in the\n * effect, so there is no render between a keystroke and the debounce in which an\n * empty list could claim \"No results\" for a question still being asked.\n */\nexport function useOptionSource<V extends string | number>({\n options,\n loadOptions,\n loading,\n filter = true,\n minChars = 0,\n debounceMs = 150,\n query,\n active,\n}: OptionSourceOptions<V> & { query: string; active: boolean }): OptionSource<V> {\n const isAsync = typeof loadOptions === \"function\";\n const tooShort = query.trim().length < minChars;\n const [settled, setSettled] = useState<{\n query: string | null;\n results: ComboOption<V>[];\n failed: boolean;\n }>({ query: null, results: [], failed: false });\n const loadRef = useRef(loadOptions);\n useEffect(() => {\n loadRef.current = loadOptions;\n });\n const reqId = useRef(0);\n\n useEffect(() => {\n // Bumped even when nothing is asked, so a request still in flight from a longer\n // query cannot land after the user has deleted back below `minChars`.\n const id = ++reqId.current;\n if (!active || !isAsync || tooShort) return;\n const t = setTimeout(\n async () => {\n try {\n const r = await loadRef.current!(query);\n if (reqId.current === id) setSettled({ query, results: r, failed: false });\n } catch {\n // The one path the old `try/finally` had no answer for: the list kept the\n // previous query's rows and said nothing (Keksdose proposal §2).\n if (reqId.current === id) setSettled({ query, results: [], failed: true });\n }\n },\n query ? debounceMs : 0,\n );\n return () => clearTimeout(t);\n }, [query, active, isAsync, tooShort, debounceMs]);\n\n const clientResults = useMemo(() => {\n if (isAsync) return [];\n const src = options ?? [];\n const q = query.trim().toLowerCase();\n if (!filter || !q) return src;\n return src.filter(\n (o) => o.label.toLowerCase().includes(q) || (o.sublabel ?? \"\").toLowerCase().includes(q),\n );\n }, [isAsync, options, query, filter]);\n\n const pending = isAsync && active && !tooShort && settled.query !== query;\n const failed = isAsync && !tooShort && settled.failed;\n return {\n results: tooShort ? [] : isAsync ? (failed ? [] : settled.results) : clientResults,\n busy: Boolean(loading) || pending,\n failed: failed && !pending,\n tooShort,\n };\n}\n\nexport type ComboboxCoreOptions<V extends string | number> = OptionSourceOptions<V>;\n\nexport interface ComboboxCore<V extends string | number> {\n triggerRef: RefObject<HTMLButtonElement | null>;\n panelRef: RefObject<HTMLDivElement | null>;\n inputRef: RefObject<HTMLInputElement | null>;\n open: boolean;\n setOpen: Dispatch<SetStateAction<boolean>>;\n query: string;\n setQuery: Dispatch<SetStateAction<string>>;\n active: number;\n setActive: Dispatch<SetStateAction<number>>;\n results: ComboOption<V>[];\n busy: boolean;\n /** See {@link OptionSource}. */\n failed: boolean;\n tooShort: boolean;\n minChars: number;\n rect: AnchorRect | null;\n /** Where the dropdown goes, clamped to the visible viewport (feedback #135). */\n placement: AnchoredPanel;\n /** Put an option in the label cache, so {@link ComboboxCore.resolve} still knows a\n * value the caller just chose after the result list has moved on. */\n rememberOption: (o: ComboOption<V>) => void;\n resolve: (v: V) => ComboOption<V> | null;\n /** Close and hand focus back to the trigger — the keyboard paths only. See\n * {@link useDropdown} for why a pointer dismissal must not do this. */\n closeToTrigger: () => void;\n}\n\n/**\n * Shared plumbing for the entity pickers: open/query/active state, portalled\n * anchoring + outside-click/Escape dismissal, focus-on-open, a debounced\n * race-safe async (or client-side) result list, and a label cache so a selected\n * value still renders its label after the async list has moved on. The single-\n * and multi-value comboboxes render their triggers on top of this and share\n * {@link ComboboxPanel} for the dropdown.\n */\nexport function useComboboxCore<V extends string | number>({\n options,\n minChars = 0,\n ...source\n}: ComboboxCoreOptions<V>): ComboboxCore<V> {\n const triggerRef = useRef<HTMLButtonElement>(null);\n const panelRef = useRef<HTMLDivElement>(null);\n const inputRef = useRef<HTMLInputElement>(null);\n const [open, setOpen] = useState(false);\n const [query, setQuery] = useState(\"\");\n const [active, setActive] = useState(0);\n\n const close = () => setOpen(false);\n // Escape unmounts the panel the user is typing in; without this the browser drops\n // focus on <body>, so the caret disappears and the next Tab restarts at the top of\n // the page. A pointer dismissal deliberately does NOT do this — the press has\n // already decided where focus belongs.\n const closeToTrigger = () => {\n setOpen(false);\n triggerRef.current?.focus();\n };\n // Placement, not just the anchor rect: the panel has to dodge the on-screen\n // keyboard its own search box summons (feedback #135).\n const placement = useAnchoredPanel(triggerRef, open);\n const rect = placement.rect;\n // Outside-click dismissal belongs to the ANCHORED panel, and only to it. On a\n // phone `ComboboxPanel` renders a full-screen `PickerSheet` instead (live #200),\n // portalled to <body> and carrying its own ways out — the close X, Escape, and\n // Back through `useOverlayHistory` — so there is no outside left to press.\n //\n // Leaving the listener on there was not merely redundant, it was the bug:\n // `panelRef` is attached to the desktop panel alone, so with the sheet up every\n // press inside it answered \"outside\". While `useOutsideClick` listened for\n // `mousedown` the rows survived by accident — they commit on `onMouseDown` too,\n // and won the race — but `pointerdown` PRECEDES `mousedown`, so the sheet closed\n // at finger-down and the commit landed on an unmounted tree: a tapped row kept the\n // old value, and tapping the search box or the X was equally fatal. `PickerSheet`\n // stops `mousedown` for exactly this reason, but that guard was written for\n // `useDropdown`'s listener and never covered this hook.\n const isPhone = useMediaQuery(PHONE_QUERY, false);\n useOutsideClick([triggerRef, panelRef], close, open && !isPhone);\n useEscapeKey(closeToTrigger, open);\n\n // Reset the query each time the panel opens, and the highlighted row whenever the\n // visible set changes (a new query, or the panel opening or closing). Adjusted while\n // rendering against the previous values rather than in an effect, so the render that\n // opens the panel already searches for \"\" and highlights the first row.\n const [prevOpen, setPrevOpen] = useState(open);\n const [prevQuery, setPrevQuery] = useState(query);\n if (open !== prevOpen || query !== prevQuery) {\n const opened = open && !prevOpen;\n setPrevOpen(open);\n setPrevQuery(opened ? \"\" : query);\n if (opened) setQuery(\"\");\n setActive(0);\n }\n\n // Focus the search box each time the panel opens.\n useEffect(() => {\n if (!open) return;\n const id = requestAnimationFrame(() => inputRef.current?.focus());\n return () => cancelAnimationFrame(id);\n }, [open]);\n\n // Debounced, race-safe async search (only when loadOptions is provided) or the\n // client-side filter — see {@link useOptionSource}.\n const { results, busy, failed, tooShort } = useOptionSource<V>({\n ...source,\n options,\n minChars,\n query,\n active: open,\n });\n\n // Accumulate every option we've seen so a selected value can render its label\n // even after the async list has moved on to other query results.\n const cacheRef = useRef(new Map<V, ComboOption<V>>());\n useEffect(() => {\n for (const o of options ?? []) cacheRef.current.set(o.value, o);\n for (const o of results) cacheRef.current.set(o.value, o);\n }, [options, results]);\n const resolve = (v: V): ComboOption<V> | null =>\n options?.find((o) => o.value === v) ?? cacheRef.current.get(v) ?? null;\n const rememberOption = (o: ComboOption<V>) => {\n cacheRef.current.set(o.value, o);\n };\n\n return {\n triggerRef,\n panelRef,\n inputRef,\n open,\n setOpen,\n query,\n setQuery,\n active,\n setActive,\n results,\n busy,\n failed,\n tooShort,\n minChars,\n rect,\n placement,\n rememberOption,\n resolve,\n closeToTrigger,\n };\n}\n\n/** The error line under a field — the same type as `ui.tsx`'s (module-private) one,\n * so a combobox's message is indistinguishable from an Input's. */\nconst FIELD_ERROR_CLASS = \"mt-1 text-[11px] leading-tight text-[var(--danger)]\";\n\n/**\n * {@link Input}'s `error` for the combobox family: the message under the field, its\n * id on the control's `aria-describedby` (merged, never replacing — the hint the\n * caller pointed at stays first), and `invalid` implied. ui.tsx's `useFieldError` is\n * module-private, so this restates it on the same rules `choice-parts.ts` does.\n */\nexport function useComboboxFieldError(\n error: ReactNode,\n invalid: boolean | undefined,\n describedBy?: string,\n) {\n const errorId = useId();\n const has = hasMessage(error);\n return {\n isInvalid: Boolean(invalid) || has,\n describedBy: mergeDescribedBy(describedBy, has && errorId),\n errorEl: has ? (\n <p id={errorId} className={FIELD_ERROR_CLASS}>\n {error}\n </p>\n ) : null,\n };\n}\n\n/** The anchored suggestion list's box and rows — one look for {@link Combobox},\n * {@link InlineEntityCombobox} and {@link Autocomplete}. */\nexport const SUGGESTION_LIST_CLASS =\n \"max-h-64 overflow-y-auto rounded-md border border-[var(--border)] bg-[var(--bg-surface)] py-1 shadow-lg\";\n\nexport const suggestionRowClass = (isActive: boolean) =>\n cn(\n \"block w-full truncate px-3 py-1.5 text-start text-sm text-[var(--text-primary)]\",\n isActive ? \"bg-[var(--bg-active)]\" : \"hover:bg-[var(--bg-hover)]\",\n );\n\n/**\n * Keep the option the keyboard is on inside the visible part of the list.\n *\n * `aria-activedescendant` moves a highlight WITHOUT moving focus, which is the whole\n * point of it — and the cost is that the browser scrolls nothing on its own. In a\n * panel capped at a few hundred pixels over an account list two hundred long, Down\n * walked the highlight straight out of the box and the list sat still.\n *\n * Optional-called because jsdom does not implement `scrollIntoView`: three consumers\n * run this component in their own suites, and a picker that throws there is a worse\n * trade than a list that does not scroll in a test.\n */\nexport function useActiveOptionScroll(activeId: string | undefined): void {\n useEffect(() => {\n if (!activeId) return;\n document.getElementById(activeId)?.scrollIntoView?.({ block: \"nearest\" });\n }, [activeId]);\n}\n\nexport interface ComboboxPanelProps<V extends string | number>\n extends ComponentPropsWithoutRef<\"div\"> {\n core: ComboboxCore<V>;\n /** What the trigger's `aria-controls` names. Owned by the component that renders\n * the trigger, not by the core: one id has to reach both, and only one of them\n * can be the origin. */\n listboxId: string;\n /** Default: `combobox.search` from the {@link UiKitProvider}, else English. */\n searchPlaceholder?: string;\n /** Default: `combobox.noResults` from the {@link UiKitProvider}, else English. */\n emptyLabel?: string;\n multi?: boolean;\n isSelected: (v: V) => boolean;\n onChoose: (o: ComboOption<V>) => void;\n showCreate: boolean;\n onCreate: () => void;\n createContent: ReactNode;\n /** What the sheet calls itself on a phone — the field's label. Ignored on\n * desktop, where the panel sits under the field that already says it. */\n sheetTitle?: ReactNode;\n closeLabel?: string;\n /** Default: `combobox.loadError` from the {@link UiKitProvider}, else English. */\n loadErrorLabel?: string;\n}\n\n/**\n * The portalled dropdown (search header + result rows + optional create row)\n * shared by the single- and multi-value comboboxes. Start-aligned to the trigger\n * and sized to its width; `multi` swaps the trailing check for a leading\n * checkbox. `onChoose` decides whether to close (single) or stay open (multi).\n *\n * ## The ARIA, which is `CommandPalette`'s\n *\n * This rendered a `role=\"listbox\"` of `role=\"option\"` rows and stopped there, so a\n * reader was handed a text box and silence: the highlight the arrow keys move lived\n * only in a background colour, and nothing tied the box being typed in to the list\n * being filtered. `CommandPalette` has had the whole model since it was written —\n * `aria-controls` from the field to the list, `aria-activedescendant` naming the row\n * the keyboard is on — and it was the only thing in the package that did.\n *\n * Two distinct states, deliberately not conflated:\n * - `aria-selected` is CHOSEN. It is the check mark, and in `multi` the checkbox.\n * - `aria-activedescendant` is where the KEYBOARD is. Announcing that as selected\n * would tell a reader that the row they are merely passing over is the answer.\n *\n * `role=\"option\"` sits on the `<button>`, not on the `<li>` around it, for the same\n * reason it does in `CommandPalette`: an option may not contain a separately\n * focusable control, and the button is the thing a pointer presses. The rows are\n * `tabIndex={-1}` because focus never leaves the search box — that is what\n * `aria-activedescendant` is FOR.\n */\nexport function ComboboxPanel<V extends string | number>({\n core,\n listboxId,\n searchPlaceholder,\n emptyLabel,\n multi,\n isSelected,\n onChoose,\n showCreate,\n onCreate,\n createContent,\n sheetTitle,\n closeLabel,\n loadErrorLabel,\n className,\n style,\n ...rest\n}: ComboboxPanelProps<V>) {\n const {\n rect,\n placement,\n panelRef,\n inputRef,\n query,\n setQuery,\n results,\n busy,\n failed,\n tooShort,\n active,\n setActive,\n closeToTrigger,\n } = core;\n // The phone gets a full-screen sheet instead of an anchored panel (live #200).\n // Same core, same results, same handlers — only the container differs, so the\n // two presentations cannot drift in what they offer.\n const isPhone = useMediaQuery(PHONE_QUERY, false);\n // Every row the keyboard can land on, the create row included (never disabled).\n const rows: readonly { disabled?: boolean }[] = showCreate ? [...results, {}] : results;\n const rowCount = rows.length;\n const optionId = (index: number) => `${listboxId}-option-${index}`;\n // The core opens on row 0 and knows nothing of `disabled`; the highlight is settled\n // HERE, derived, so it can never rest on a row that cannot be taken — whatever the\n // async list turned out to hold.\n const current = settleEnabled(rows, active);\n const activeId = current >= 0 ? optionId(current) : undefined;\n useActiveOptionScroll(activeId);\n // The consumers resolve their own props against the provider already; this is\n // for the loading row, which no consumer names, and for a caller that renders the\n // panel directly and leaves the two optional strings out.\n const labels = useKitLabels(\"combobox\", DEFAULT_COMBOBOX_LABELS);\n // Portalled to <body>, the panel leaves the subtree its `dir` came from — so the\n // direction is read off the trigger and put back on the panel below.\n const dir = useAnchorDir(core.triggerRef, core.open);\n\n // The WAI-ARIA APG's listbox keyboard, in full: Up/Down step, Home/End jump, Enter\n // commits, Tab leaves. Escape is the one key handled elsewhere — `useComboboxCore`\n // registers it on the document, so it answers wherever focus has ended up.\n const onKeyDown = (e: ReactKeyboardEvent) => {\n // Disabled rows are passed over (`stepEnabled`), and each step starts from the\n // SETTLED highlight, not the raw index, so the first Down from a disabled row 0\n // goes to the row after the one already shown as highlighted.\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n setActive(stepEnabled(rows, current, 1));\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n setActive(current < 0 ? -1 : stepEnabled(rows, current, -1));\n } else if (e.key === \"Home\") {\n e.preventDefault();\n setActive(stepEnabled(rows, -1, 1));\n } else if (e.key === \"End\") {\n e.preventDefault();\n setActive(stepEnabled(rows, rowCount, -1));\n } else if (e.key === \"Enter\") {\n e.preventDefault();\n if (current < 0) return;\n if (current < results.length) onChoose(results[current]);\n else if (showCreate) onCreate();\n } else if (e.key === \"Tab\") {\n // The panel is PORTALLED to <body>, so the browser's own Tab would move from\n // here to whatever follows the portal — i.e. off the end of the document. The\n // trade is one extra Tab (trigger, then onward) against never stranding focus\n // at the bottom of the page.\n e.preventDefault();\n closeToTrigger();\n }\n };\n\n // What the list holds, said in ONE place that is both on screen and a polite\n // live region. Focus stays in the search box, so the list changing under it was\n // silent — a reader typed and heard nothing back, and a failed lookup was the same\n // silence as a slow one. Outside the listbox, which may own only options.\n //\n // Three different empties, and only one of them is \"nothing matched\": a lookup\n // that failed must not claim there is nothing to find, and a query under\n // `minChars` was never asked. With rows showing, the count is for the reader only.\n const message: ReactNode =\n busy && results.length === 0 ? (\n // The ellipsis is the picture; the words are for a reader, who otherwise met\n // an empty-looking list with a lone \"…\" in it — or, in most readers, nothing\n // at all, since punctuation alone is skipped.\n <>\n <span aria-hidden>…</span>\n <span className=\"sr-only\">{labels.loading}</span>\n </>\n ) : busy ? (\n // Loading with the LAST query's rows still up. This was `null`, so a refetch —\n // a new query, or a caller's `loading` while it reloads — looked exactly like a\n // finished list: rows that were about to be replaced, with nothing saying so.\n // A line of its own under the rows, in words, so it reads without the spinner.\n <span className=\"flex items-center gap-2\">\n <Spinner label={null} className=\"size-3.5 border\" />\n {labels.loading}\n </span>\n ) : results.length === 0 && !showCreate ? (\n failed ? (\n (loadErrorLabel ?? labels.loadError)\n ) : tooShort ? (\n labels.minChars(core.minChars)\n ) : (\n (emptyLabel ?? labels.noResults)\n )\n ) : null;\n // `relative` so the sr-only text has a local containing block (see\n // sr-only-containment.test).\n const announcement = (\n <div\n role=\"status\"\n aria-live=\"polite\"\n className={cn(\n \"relative\",\n message !== null && cn(\"py-2 text-sm\", isPhone ? \"px-4\" : \"px-3\"),\n failed ? \"text-[var(--danger)]\" : \"text-[var(--text-muted)]\",\n )}\n >\n {message ??\n (results.length > 0 && (\n <span className=\"sr-only\">{labels.resultCount(results.length)}</span>\n ))}\n </div>\n );\n\n if (!core.open || typeof document === \"undefined\") return null;\n\n const list = (\n <ul\n id={listboxId}\n role=\"listbox\"\n aria-multiselectable={multi}\n // The rows are provisional while a lookup is in flight — whether or not the\n // previous query's are still showing.\n aria-busy={busy || undefined}\n // It scrolls, and says so where jsdom can see it (see `CLIPS_ATTRIBUTE`): a\n // Tooltip in a row then portals out in a test exactly as it does in the\n // browser, instead of joining the option's accessible name (keksdose E8).\n {...{ [CLIPS_ATTRIBUTE]: \"\" }}\n className={cn(\"min-h-0 flex-1 overflow-y-auto py-1\", isPhone && \"flex-none\")}\n >\n {results.map((o, i) => {\n const selected = isSelected(o.value);\n // One heading per group rather than a grey suffix on every row (#136), and\n // the thing the native <select>'s <optgroup> used to give the account\n // picker for free (live #200). `results` keeps its source order, so a\n // boundary is simply \"different from the row above\".\n const startsGroup = o.group != null && o.group !== results[i - 1]?.group;\n return (\n // Keyed by group AND value: an option may deliberately appear twice —\n // Keksdose repeats recently-used categories in a \"Recent\" group at the\n // top (live #203) — and a bare value key would collide.\n <Fragment key={`${o.group ?? \"\"}|${String(o.value)}`}>\n {startsGroup && (\n <li\n role=\"presentation\"\n className={cn(\n \"font-semibold uppercase tracking-wide text-[var(--text-muted)]\",\n isPhone ? \"px-4 pb-1 pt-3 text-xs\" : \"px-3 pb-0.5 pt-2 text-[11px] first:pt-1\",\n )}\n >\n {o.group}\n </li>\n )}\n <li role=\"presentation\">\n <button\n type=\"button\"\n id={optionId(i)}\n role=\"option\"\n aria-selected={selected}\n aria-disabled={o.disabled || undefined}\n tabIndex={-1}\n onMouseDown={(e) => {\n e.preventDefault();\n if (!o.disabled) onChoose(o);\n }}\n onMouseEnter={() => {\n if (!o.disabled) setActive(i);\n }}\n className={cn(\n isPhone\n ? SHEET_ROW_CLASS\n : \"flex w-full items-center gap-2 px-3 py-1.5 text-start text-sm\",\n o.disabled\n ? DISABLED_ROW_CLASS\n : i === current && !isPhone\n ? \"bg-[var(--bg-active)]\"\n : !isPhone && \"hover:bg-[var(--bg-hover)]\",\n // After SHEET_ROW_CLASS, so its hover is the one cancelled.\n o.disabled && isPhone && DISABLED_ROW_CLASS,\n )}\n >\n {multi && (\n <span\n // The checkbox is a PICTURE of `aria-selected` above, so a reader\n // that met both would be told twice.\n aria-hidden\n className={cn(\n \"flex size-4 shrink-0 items-center justify-center rounded border\",\n selected\n ? \"border-[var(--bg-inverse)] bg-[var(--bg-inverse)] text-[var(--text-inverse)]\"\n : \"border-[var(--border-strong)] bg-[var(--bg-surface)]\",\n )}\n >\n {selected && <Check className=\"size-3\" />}\n </span>\n )}\n {o.icon && <span className=\"shrink-0\">{o.icon}</span>}\n <span className=\"min-w-0 flex-1\">\n <span className=\"block truncate text-[var(--text-primary)]\">{o.label}</span>\n {o.sublabel && (\n <span className=\"block truncate text-xs text-[var(--text-placeholder)]\">\n {o.sublabel}\n </span>\n )}\n </span>\n {!multi && selected && <Check className=\"size-4 shrink-0 text-[var(--brand)]\" />}\n </button>\n </li>\n </Fragment>\n );\n })}\n {showCreate && (\n <li role=\"presentation\">\n <button\n type=\"button\"\n id={optionId(results.length)}\n role=\"option\"\n // Never chosen — it is an action, and it disappears the moment it has\n // been taken. Whether the keyboard is ON it is `aria-activedescendant`'s\n // job to say.\n aria-selected={false}\n tabIndex={-1}\n onMouseDown={(e) => {\n e.preventDefault();\n onCreate();\n }}\n onMouseEnter={() => setActive(results.length)}\n className={cn(\n isPhone\n ? SHEET_ROW_CLASS\n : \"flex w-full items-center gap-2 px-3 py-1.5 text-start text-sm\",\n \"text-[var(--text-secondary)]\",\n current === results.length && !isPhone\n ? \"bg-[var(--bg-active)]\"\n : !isPhone && \"hover:bg-[var(--bg-hover)]\",\n )}\n >\n <Plus className=\"size-4 shrink-0\" />\n <span className=\"truncate\">{createContent}</span>\n </button>\n </li>\n )}\n </ul>\n );\n\n if (isPhone) {\n return (\n <PickerSheet\n // First, so the sheet's own props below win: `rest` is typed as div\n // attributes, and the DOM's `title` is a tooltip string where the sheet's is\n // its heading — one name, two meanings, and the sheet's is the one the caller\n // asked for.\n {...rest}\n className={className}\n style={style}\n open\n onClose={() => core.setOpen(false)}\n title={sheetTitle}\n query={query}\n onQueryChange={setQuery}\n searchPlaceholder={searchPlaceholder ?? labels.search}\n inputRef={inputRef}\n closeLabel={closeLabel}\n >\n {/* eslint-disable-next-line jsx-a11y/no-static-element-interactions -- never focused\n itself: it catches the listbox keys bubbling from the sheet's search <input>,\n which holds focus while the list is up. */}\n <div onKeyDown={onKeyDown} className=\"relative\">\n {list}\n {announcement}\n </div>\n </PickerSheet>\n );\n }\n\n if (!rect) return null;\n // The panel hangs from the trigger's START edge: its left in a left-to-right form,\n // its right in a right-to-left one (it may be wider than the trigger, `minWidth`).\n // `clientWidth` rather than `innerWidth`, because a fixed box's `right` is measured\n // from the edge of the viewport inside any scrollbar.\n const inline =\n dir === \"rtl\"\n ? { right: (document.documentElement.clientWidth || window.innerWidth) - rect.right }\n : { left: rect.left };\n\n return createPortal(\n /* eslint-disable-next-line jsx-a11y/no-static-element-interactions -- never focused\n itself: it catches the listbox keys bubbling from the search <input> inside it,\n which holds focus while the panel is open. */\n <div\n // Spread FIRST: `onKeyDown` below is the listbox keyboard (Up/Down/Home/End/\n // Enter/Tab) and the placement is measured rather than chosen, so neither is a\n // caller's to replace by accident — while a `data-*` anchor or an\n // `aria-describedby` has nothing to collide with.\n {...rest}\n ref={panelRef}\n dir={dir}\n onKeyDown={onKeyDown}\n // `placement` keeps the panel inside the region actually on screen: on a phone\n // the search box below pulls up the keyboard, and a panel pinned under a\n // low trigger would otherwise sit entirely behind it (feedback #135).\n style={{\n ...style,\n position: \"fixed\",\n top: placement.top,\n ...inline,\n width: rect.width,\n minWidth: 220,\n maxHeight: placement.maxHeight,\n }}\n className={cn(\n \"z-50 flex flex-col rounded-md border border-[var(--border)] bg-[var(--bg-surface)] shadow-lg\",\n className,\n )}\n >\n <DropdownSearchHeader\n query={query}\n onQueryChange={setQuery}\n inputRef={inputRef}\n placeholder={searchPlaceholder ?? labels.search}\n // Focus is in this box while the list is up, so this is what has to name the\n // list and the row the arrows are on.\n listboxId={listboxId}\n activeId={activeId}\n />\n {/* One list, two containers: the desktop panel and the phone sheet render\n the same rows through the same handlers (live #200). */}\n {list}\n {announcement}\n </div>,\n document.body,\n );\n}\n"],"mappings":";AAsHI,SAmeE,U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QACJ;AAAA,QACA;AAAA,QACA,MAAI;AAAA,QACJ,SAAS,MAAM,KAAK,QAAQ,KAAK;AAAA,QACjC,OAAO;AAAA,QACP;AAAA,QACA,eAAe;AAAA,QACf,mBAAmB,qBAAqB,OAAO;AAAA,QAC/C;AAAA,QACA;AAAA,QAKA,+BAAC,SAAI,WAAsB,WAAU,YAClC;AAAA;AAAA,UACA;AAAA,WACH;AAAA;AAAA,IACF;AAAA,EAEJ;AAEA,MAAI,CAAC,KAAM,QAAO;AAKlB,QAAM,SACJ,QAAQ,QACJ,EAAE,QAAQ,SAAS,gBAAgB,eAAe,OAAO,cAAc,KAAK,MAAM,IAClF,EAAE,MAAM,KAAK,KAAK;AAExB,SAAO;AAAA;AAAA;AAAA;AAAA,IAIL;AAAA,MAAC;AAAA;AAAA,QAKE,GAAG;AAAA,QACJ,KAAK;AAAA,QACL;AAAA,QACA;AAAA,QAIA,OAAO;AAAA,UACL,GAAG;AAAA,UACH,UAAU;AAAA,UACV,KAAK,UAAU;AAAA,UACf,GAAG;AAAA,UACH,OAAO,KAAK;AAAA,UACZ,UAAU;AAAA,UACV,WAAW,UAAU;AAAA,QACvB;AAAA,QACA,WAAW;AAAA,UACT;AAAA,UACA;AAAA,QACF;AAAA,QAEA;AAAA;AAAA,YAAC;AAAA;AAAA,cACC;AAAA,cACA,eAAe;AAAA,cACf;AAAA,cACA,aAAa,qBAAqB,OAAO;AAAA,cAGzC;AAAA,cACA;AAAA;AAAA,UACF;AAAA,UAGC;AAAA,UACA;AAAA;AAAA;AAAA,IACH;AAAA,IACA,SAAS;AAAA,EACX;AACF;","names":["Fragment"]}
|
|
1
|
+
{"version":3,"sources":["../../src/components/combobox-core.tsx"],"sourcesContent":["import { Fragment, useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport type {\n ComponentPropsWithoutRef,\n Dispatch,\n KeyboardEvent as ReactKeyboardEvent,\n ReactNode,\n RefObject,\n SetStateAction,\n} from \"react\";\nimport { Check, Plus } from \"lucide-react\";\nimport { cn } from \"../lib/cn\";\nimport { CLIPS_ATTRIBUTE } from \"../lib/clipping\";\nimport { DropdownSearchHeader } from \"./dropdown\";\nimport { PickerSheet, SHEET_ROW_CLASS } from \"./picker-sheet\";\nimport { useMediaQuery } from \"../hooks/use-media-query\";\nimport { FLOATING_LABEL_STATIC, PHONE_QUERY, Spinner } from \"./ui\";\nimport { useAnchorDir } from \"./use-anchor-dir\";\nimport { type AnchorRect } from \"../hooks/use-anchored-rect\";\nimport { useAnchoredPanel, type AnchoredPanel } from \"../hooks/use-anchored-panel\";\nimport { useEscapeKey, useOutsideClick } from \"../hooks/use-dismiss\";\nimport { DEFAULT_COMBOBOX_LABELS, useKitLabels } from \"../i18n/kit-labels\";\nimport { hasMessage, mergeDescribedBy } from \"./choice-parts\";\n\n/**\n * What an entity picker hands `onChange` when it is cleared — `clearValue` on\n * {@link EntityCombobox} and {@link InlineEntityCombobox}. `null` by default.\n *\n * A closed set rather than any value, on purpose: every member is something no\n * option can be (an option's value is a `string | number`, and `\"\"` is never a real\n * id), so the picker can also READ it back — a field whose `value` is the clear\n * value shows as empty, with no clear button, exactly as `null` does. An arbitrary\n * sentinel could collide with an id and would make that read ambiguous.\n *\n * No `undefined`: a prop set to `undefined` is a prop not passed, so it would read as\n * the default and emit `null` — the one outcome the caller had asked not to get.\n */\nexport type ComboClearValue = null | \"\";\n\nexport interface ComboOption<V extends string | number> {\n value: V;\n label: string;\n sublabel?: string;\n icon?: ReactNode;\n /**\n * Section this option belongs to. Where a consumer renders it as a heading with the\n * members indented beneath — {@link InlineEntityCombobox} does — this is a genuine\n * grouping, not decoration: the name appears once per section rather than trailing\n * every row in small grey type, which is barely legible on a phone (feedback #136).\n * Searchable like `sublabel`.\n */\n group?: string;\n /**\n * Shown but not takeable: rendered dimmed with `aria-disabled`, passed over by the\n * arrow keys, and a click or Enter on it does nothing. For a row whose existence is\n * the information — a write-locked result, an account that is closed — where\n * leaving it out would read as \"there is no such thing\". Say WHY in `sublabel`: a\n * hover tooltip is the one explanation a phone cannot show.\n *\n * Honoured by {@link Autocomplete}, {@link InlineEntityCombobox} and the panel\n * pickers ({@link EntityCombobox}, {@link MultiEntityCombobox}); on those an already\n * chosen disabled option stays chosen — the row only refuses to be toggled.\n */\n disabled?: boolean;\n}\n\n/** A row the user may take — present and not {@link ComboOption.disabled}. */\nexport const isOptionEnabled = (o: { disabled?: boolean } | undefined): boolean =>\n o !== undefined && !o.disabled;\n\n/**\n * The next takeable row from `from`, stepping `dir` — what the arrow keys use so a\n * disabled row is passed over, as the APG allows. Stays on `from` at the end of the\n * list (the family's arrows clamp rather than wrap) and answers `-1` when `from` is\n * not a row and there is nothing to step to.\n */\nexport function stepEnabled(\n rows: readonly { disabled?: boolean }[],\n from: number,\n dir: 1 | -1,\n): number {\n for (let i = from + dir; i >= 0 && i < rows.length; i += dir) {\n if (!rows[i].disabled) return i;\n }\n return from >= 0 && from < rows.length ? from : -1;\n}\n\n/** `i` when that row is takeable, else the nearest takeable one after it, else\n * before it, else `-1`. For a highlight that starts on a fixed index (the panel\n * pickers open on row 0) and must never rest on a disabled row. */\nexport function settleEnabled(rows: readonly { disabled?: boolean }[], i: number): number {\n if (i < 0 || i >= rows.length) return -1;\n if (!rows[i].disabled) return i;\n const after = stepEnabled(rows, i, 1);\n if (after !== i) return after;\n const before = stepEnabled(rows, i, -1);\n return before !== i ? before : -1;\n}\n\n/** Classes a disabled row adds over its normal ones — dimmed, no hover, the\n * kit's soft-disabled look (`DangerConfirm`, `SignaturePad`). */\nexport const DISABLED_ROW_CLASS = \"cursor-not-allowed opacity-50 hover:bg-transparent\";\n\n/**\n * Whether an entity picker offers its create row — one rule for\n * {@link EntityCombobox}, {@link MultiEntityCombobox} and {@link InlineEntityCombobox}.\n *\n * With a query: while the trimmed query names no option exactly (case-insensitive) —\n * an exact hit is a record the list is already showing, and a second way to \"make\" it\n * would mint a duplicate. With NO query: only when the caller named the row for that\n * case (`createEmptyLabel`) — a row reading `Create “”` says nothing, and the kit cannot\n * know the noun (\"Create cash account\") that would make it say something (keksdose G9).\n *\n * `names` is what the query is compared against: the loaded rows for a panel picker\n * (its async list is all it knows), every option for the inline one.\n */\nexport function offersCreate(\n onCreate: unknown,\n query: string,\n names: readonly string[],\n createEmptyLabel: string | undefined,\n): boolean {\n if (!onCreate) return false;\n if (!query) return Boolean(createEmptyLabel);\n const q = query.toLowerCase();\n return !names.some((n) => n.toLowerCase() === q);\n}\n\n/**\n * {@link EndHintRow}'s `hint` and `className` for a combobox-family field, keeping the\n * 0.22 rule (keksdose): a field that was passed `hint` at all — even `undefined` — keeps\n * ONE box, so a hint coming and going never rebuilds the control under the cursor.\n *\n * A text hint is a caption after the control and never moved it; the case this covers\n * is the \"?\" (a {@link FieldHint}) on a field with no label line, which sits at the end\n * edge in a row of its own. Without this the row existed only while the \"?\" did, and\n * the control was re-parented — remounted, focus and caret lost — each time it came or\n * went. With `hint` passed the row stays, its end slot empty and its gap closed, so\n * nothing on screen moves either.\n */\nexport function endHintRowProps(\n hintPassed: boolean,\n hasLabel: boolean,\n labelHint: ReactNode | undefined,\n): { hint: ReactNode | undefined; className?: string } {\n if (hasLabel) return { hint: undefined };\n if (labelHint !== undefined) return { hint: labelHint };\n return hintPassed ? { hint: null, className: \"gap-0\" } : { hint: undefined };\n}\n\n/**\n * The family's floating label, as a real `<label for>` (lenkbank): the input is then\n * named the way {@link Input}'s is, so `getByLabelText` and any helper that walks\n * `<label htmlFor>` finds it. Same placement and type as {@link FieldLabel}, which\n * stays a `<span>` for the TRIGGER pickers — a `<button>` is labelable, but those\n * compose their own \"label: value\" name. `pointer-events-none` (from the class)\n * keeps a press on it landing on the field under it, as before.\n */\nexport function ComboboxFieldLabel({\n htmlFor,\n className,\n children,\n ...rest\n}: ComponentPropsWithoutRef<\"label\"> & { htmlFor: string }) {\n return (\n <label {...rest} htmlFor={htmlFor} className={cn(FLOATING_LABEL_STATIC, \"z-10\", className)}>\n {children}\n </label>\n );\n}\n\n/**\n * Where a combobox's rows come from, and how a query narrows them. Shared by the\n * trigger pickers ({@link useComboboxCore}) and the inline {@link Autocomplete}, so\n * the two cannot drift in what a failed lookup or a too-short query does.\n */\nexport interface OptionSourceOptions<V extends string | number> {\n /** Already-loaded options (client-side filtered unless `filter` is false), also\n * used to resolve labels. */\n options?: ComboOption<V>[];\n /** Async option source, debounced and race-safe; stale responses are ignored,\n * and a rejection is caught and reported as `failed`. */\n loadOptions?: (query: string) => Promise<ComboOption<V>[]>;\n /** External loading flag, OR-ed with the internal async state. */\n loading?: boolean;\n /**\n * Narrow `options` by the query (label/sublabel substring). Default `true`.\n *\n * `false` shows `options` exactly as given, in the given order — for a list the\n * caller has already searched and ranked on a server (Keksdose's geocoder), which a\n * second, client-side substring filter could only get wrong: a provider that\n * matches \"Bahnhofstr.\" to \"Bahnhofstrasse\" is right, and a label filter would\n * throw that row away.\n */\n filter?: boolean;\n /**\n * Below this many (trimmed) characters nothing is offered and `loadOptions` is not\n * called. Default `0` — the pickers list everything on open. Set it for a source\n * that is costly or rate-limited: one letter against a geocoder matches half a\n * continent, and a request per opened panel is a request nobody asked for.\n */\n minChars?: number;\n /** Quiet time after the last keystroke before `loadOptions` runs. Default 150 ms. */\n debounceMs?: number;\n}\n\nexport interface OptionSource<V extends string | number> {\n results: ComboOption<V>[];\n busy: boolean;\n /** The last lookup for this query REJECTED. The rows are emptied with it: results\n * from an earlier query under a failed one would read as the answer to it. */\n failed: boolean;\n /** The query is shorter than `minChars`, so nothing was asked. */\n tooShort: boolean;\n}\n\n/**\n * The rows half of a combobox: client-side filtering, or a debounced, race-safe\n * `loadOptions` with its loading and failure states.\n *\n * `active` gates the async side — a closed list asks nothing. Loading is DERIVED\n * (\"the settled answer is for a different query\") rather than flagged on in the\n * effect, so there is no render between a keystroke and the debounce in which an\n * empty list could claim \"No results\" for a question still being asked.\n */\nexport function useOptionSource<V extends string | number>({\n options,\n loadOptions,\n loading,\n filter = true,\n minChars = 0,\n debounceMs = 150,\n query,\n active,\n}: OptionSourceOptions<V> & { query: string; active: boolean }): OptionSource<V> {\n const isAsync = typeof loadOptions === \"function\";\n const tooShort = query.trim().length < minChars;\n const [settled, setSettled] = useState<{\n query: string | null;\n results: ComboOption<V>[];\n failed: boolean;\n }>({ query: null, results: [], failed: false });\n const loadRef = useRef(loadOptions);\n useEffect(() => {\n loadRef.current = loadOptions;\n });\n const reqId = useRef(0);\n\n useEffect(() => {\n // Bumped even when nothing is asked, so a request still in flight from a longer\n // query cannot land after the user has deleted back below `minChars`.\n const id = ++reqId.current;\n if (!active || !isAsync || tooShort) return;\n const t = setTimeout(\n async () => {\n try {\n const r = await loadRef.current!(query);\n if (reqId.current === id) setSettled({ query, results: r, failed: false });\n } catch {\n // The one path the old `try/finally` had no answer for: the list kept the\n // previous query's rows and said nothing (Keksdose proposal §2).\n if (reqId.current === id) setSettled({ query, results: [], failed: true });\n }\n },\n query ? debounceMs : 0,\n );\n return () => clearTimeout(t);\n }, [query, active, isAsync, tooShort, debounceMs]);\n\n const clientResults = useMemo(() => {\n if (isAsync) return [];\n const src = options ?? [];\n const q = query.trim().toLowerCase();\n if (!filter || !q) return src;\n return src.filter(\n (o) => o.label.toLowerCase().includes(q) || (o.sublabel ?? \"\").toLowerCase().includes(q),\n );\n }, [isAsync, options, query, filter]);\n\n const pending = isAsync && active && !tooShort && settled.query !== query;\n const failed = isAsync && !tooShort && settled.failed;\n return {\n results: tooShort ? [] : isAsync ? (failed ? [] : settled.results) : clientResults,\n busy: Boolean(loading) || pending,\n failed: failed && !pending,\n tooShort,\n };\n}\n\nexport type ComboboxCoreOptions<V extends string | number> = OptionSourceOptions<V>;\n\nexport interface ComboboxCore<V extends string | number> {\n triggerRef: RefObject<HTMLButtonElement | null>;\n panelRef: RefObject<HTMLDivElement | null>;\n inputRef: RefObject<HTMLInputElement | null>;\n open: boolean;\n setOpen: Dispatch<SetStateAction<boolean>>;\n query: string;\n setQuery: Dispatch<SetStateAction<string>>;\n active: number;\n setActive: Dispatch<SetStateAction<number>>;\n results: ComboOption<V>[];\n busy: boolean;\n /** See {@link OptionSource}. */\n failed: boolean;\n tooShort: boolean;\n minChars: number;\n rect: AnchorRect | null;\n /** Where the dropdown goes, clamped to the visible viewport (feedback #135). */\n placement: AnchoredPanel;\n /** Put an option in the label cache, so {@link ComboboxCore.resolve} still knows a\n * value the caller just chose after the result list has moved on. */\n rememberOption: (o: ComboOption<V>) => void;\n resolve: (v: V) => ComboOption<V> | null;\n /** Close and hand focus back to the trigger — the keyboard paths only. See\n * {@link useDropdown} for why a pointer dismissal must not do this. */\n closeToTrigger: () => void;\n}\n\n/**\n * Shared plumbing for the entity pickers: open/query/active state, portalled\n * anchoring + outside-click/Escape dismissal, focus-on-open, a debounced\n * race-safe async (or client-side) result list, and a label cache so a selected\n * value still renders its label after the async list has moved on. The single-\n * and multi-value comboboxes render their triggers on top of this and share\n * {@link ComboboxPanel} for the dropdown.\n */\nexport function useComboboxCore<V extends string | number>({\n options,\n minChars = 0,\n ...source\n}: ComboboxCoreOptions<V>): ComboboxCore<V> {\n const triggerRef = useRef<HTMLButtonElement>(null);\n const panelRef = useRef<HTMLDivElement>(null);\n const inputRef = useRef<HTMLInputElement>(null);\n const [open, setOpen] = useState(false);\n const [query, setQuery] = useState(\"\");\n const [active, setActive] = useState(0);\n\n const close = () => setOpen(false);\n // Escape unmounts the panel the user is typing in; without this the browser drops\n // focus on <body>, so the caret disappears and the next Tab restarts at the top of\n // the page. A pointer dismissal deliberately does NOT do this — the press has\n // already decided where focus belongs.\n const closeToTrigger = () => {\n setOpen(false);\n triggerRef.current?.focus();\n };\n // Placement, not just the anchor rect: the panel has to dodge the on-screen\n // keyboard its own search box summons (feedback #135).\n const placement = useAnchoredPanel(triggerRef, open);\n const rect = placement.rect;\n // Outside-click dismissal belongs to the ANCHORED panel, and only to it. On a\n // phone `ComboboxPanel` renders a full-screen `PickerSheet` instead (live #200),\n // portalled to <body> and carrying its own ways out — the close X, Escape, and\n // Back through `useOverlayHistory` — so there is no outside left to press.\n //\n // Leaving the listener on there was not merely redundant, it was the bug:\n // `panelRef` is attached to the desktop panel alone, so with the sheet up every\n // press inside it answered \"outside\". While `useOutsideClick` listened for\n // `mousedown` the rows survived by accident — they commit on `onMouseDown` too,\n // and won the race — but `pointerdown` PRECEDES `mousedown`, so the sheet closed\n // at finger-down and the commit landed on an unmounted tree: a tapped row kept the\n // old value, and tapping the search box or the X was equally fatal. `PickerSheet`\n // stops `mousedown` for exactly this reason, but that guard was written for\n // `useDropdown`'s listener and never covered this hook.\n const isPhone = useMediaQuery(PHONE_QUERY, false);\n useOutsideClick([triggerRef, panelRef], close, open && !isPhone);\n useEscapeKey(closeToTrigger, open);\n\n // Reset the query each time the panel opens, and the highlighted row whenever the\n // visible set changes (a new query, or the panel opening or closing). Adjusted while\n // rendering against the previous values rather than in an effect, so the render that\n // opens the panel already searches for \"\" and highlights the first row.\n const [prevOpen, setPrevOpen] = useState(open);\n const [prevQuery, setPrevQuery] = useState(query);\n if (open !== prevOpen || query !== prevQuery) {\n const opened = open && !prevOpen;\n setPrevOpen(open);\n setPrevQuery(opened ? \"\" : query);\n if (opened) setQuery(\"\");\n setActive(0);\n }\n\n // Focus the search box each time the panel opens.\n useEffect(() => {\n if (!open) return;\n const id = requestAnimationFrame(() => inputRef.current?.focus());\n return () => cancelAnimationFrame(id);\n }, [open]);\n\n // Debounced, race-safe async search (only when loadOptions is provided) or the\n // client-side filter — see {@link useOptionSource}.\n const { results, busy, failed, tooShort } = useOptionSource<V>({\n ...source,\n options,\n minChars,\n query,\n active: open,\n });\n\n // Accumulate every option we've seen so a selected value can render its label\n // even after the async list has moved on to other query results.\n const cacheRef = useRef(new Map<V, ComboOption<V>>());\n useEffect(() => {\n for (const o of options ?? []) cacheRef.current.set(o.value, o);\n for (const o of results) cacheRef.current.set(o.value, o);\n }, [options, results]);\n const resolve = (v: V): ComboOption<V> | null =>\n options?.find((o) => o.value === v) ?? cacheRef.current.get(v) ?? null;\n const rememberOption = (o: ComboOption<V>) => {\n cacheRef.current.set(o.value, o);\n };\n\n return {\n triggerRef,\n panelRef,\n inputRef,\n open,\n setOpen,\n query,\n setQuery,\n active,\n setActive,\n results,\n busy,\n failed,\n tooShort,\n minChars,\n rect,\n placement,\n rememberOption,\n resolve,\n closeToTrigger,\n };\n}\n\n/** The error line under a field — the same type as `ui.tsx`'s (module-private) one,\n * so a combobox's message is indistinguishable from an Input's. */\nconst FIELD_ERROR_CLASS = \"mt-1 text-[11px] leading-tight text-[var(--danger)]\";\n\n/**\n * {@link Input}'s `error` for the combobox family: the message under the field, its\n * id on the control's `aria-describedby` (merged, never replacing — the hint the\n * caller pointed at stays first), and `invalid` implied. ui.tsx's `useFieldError` is\n * module-private, so this restates it on the same rules `choice-parts.ts` does.\n */\nexport function useComboboxFieldError(\n error: ReactNode,\n invalid: boolean | undefined,\n describedBy?: string,\n) {\n const errorId = useId();\n const has = hasMessage(error);\n return {\n isInvalid: Boolean(invalid) || has,\n describedBy: mergeDescribedBy(describedBy, has && errorId),\n errorEl: has ? (\n <p id={errorId} className={FIELD_ERROR_CLASS}>\n {error}\n </p>\n ) : null,\n };\n}\n\n/** The anchored suggestion list's box and rows — one look for {@link Combobox},\n * {@link InlineEntityCombobox} and {@link Autocomplete}. */\nexport const SUGGESTION_LIST_CLASS =\n \"max-h-64 overflow-y-auto rounded-md border border-[var(--border)] bg-[var(--bg-surface)] py-1 shadow-lg\";\n\nexport const suggestionRowClass = (isActive: boolean) =>\n cn(\n \"block w-full truncate px-3 py-1.5 text-start text-sm text-[var(--text-primary)]\",\n isActive ? \"bg-[var(--bg-active)]\" : \"hover:bg-[var(--bg-hover)]\",\n );\n\n/**\n * Keep the option the keyboard is on inside the visible part of the list.\n *\n * `aria-activedescendant` moves a highlight WITHOUT moving focus, which is the whole\n * point of it — and the cost is that the browser scrolls nothing on its own. In a\n * panel capped at a few hundred pixels over an account list two hundred long, Down\n * walked the highlight straight out of the box and the list sat still.\n *\n * Optional-called because jsdom does not implement `scrollIntoView`: three consumers\n * run this component in their own suites, and a picker that throws there is a worse\n * trade than a list that does not scroll in a test.\n */\nexport function useActiveOptionScroll(activeId: string | undefined): void {\n useEffect(() => {\n if (!activeId) return;\n document.getElementById(activeId)?.scrollIntoView?.({ block: \"nearest\" });\n }, [activeId]);\n}\n\nexport interface ComboboxPanelProps<V extends string | number>\n extends ComponentPropsWithoutRef<\"div\"> {\n core: ComboboxCore<V>;\n /** What the trigger's `aria-controls` names. Owned by the component that renders\n * the trigger, not by the core: one id has to reach both, and only one of them\n * can be the origin. */\n listboxId: string;\n /** Default: `combobox.search` from the {@link UiKitProvider}, else English. */\n searchPlaceholder?: string;\n /** Default: `combobox.noResults` from the {@link UiKitProvider}, else English. */\n emptyLabel?: string;\n multi?: boolean;\n isSelected: (v: V) => boolean;\n onChoose: (o: ComboOption<V>) => void;\n showCreate: boolean;\n onCreate: () => void;\n createContent: ReactNode;\n /**\n * The create row is shown but not takeable, and this says why — the lock's reason\n * when the picker's `createCommit` meets a locked {@link WriteLockProvider}. Rendered\n * as the row's second line rather than a tooltip, as {@link ComboOption.disabled}\n * asks of every disabled row: a hover is the one explanation a phone cannot show.\n */\n createDisabledReason?: ReactNode;\n /** What the sheet calls itself on a phone — the field's label. Ignored on\n * desktop, where the panel sits under the field that already says it. */\n sheetTitle?: ReactNode;\n closeLabel?: string;\n /** Default: `combobox.loadError` from the {@link UiKitProvider}, else English. */\n loadErrorLabel?: string;\n}\n\n/**\n * The portalled dropdown (search header + result rows + optional create row)\n * shared by the single- and multi-value comboboxes. Start-aligned to the trigger\n * and sized to its width; `multi` swaps the trailing check for a leading\n * checkbox. `onChoose` decides whether to close (single) or stay open (multi).\n *\n * ## The ARIA, which is `CommandPalette`'s\n *\n * This rendered a `role=\"listbox\"` of `role=\"option\"` rows and stopped there, so a\n * reader was handed a text box and silence: the highlight the arrow keys move lived\n * only in a background colour, and nothing tied the box being typed in to the list\n * being filtered. `CommandPalette` has had the whole model since it was written —\n * `aria-controls` from the field to the list, `aria-activedescendant` naming the row\n * the keyboard is on — and it was the only thing in the package that did.\n *\n * Two distinct states, deliberately not conflated:\n * - `aria-selected` is CHOSEN. It is the check mark, and in `multi` the checkbox.\n * - `aria-activedescendant` is where the KEYBOARD is. Announcing that as selected\n * would tell a reader that the row they are merely passing over is the answer.\n *\n * `role=\"option\"` sits on the `<button>`, not on the `<li>` around it, for the same\n * reason it does in `CommandPalette`: an option may not contain a separately\n * focusable control, and the button is the thing a pointer presses. The rows are\n * `tabIndex={-1}` because focus never leaves the search box — that is what\n * `aria-activedescendant` is FOR.\n */\nexport function ComboboxPanel<V extends string | number>({\n core,\n listboxId,\n searchPlaceholder,\n emptyLabel,\n multi,\n isSelected,\n onChoose,\n showCreate,\n onCreate,\n createContent,\n createDisabledReason,\n sheetTitle,\n closeLabel,\n loadErrorLabel,\n className,\n style,\n ...rest\n}: ComboboxPanelProps<V>) {\n const createLocked = hasMessage(createDisabledReason);\n const {\n rect,\n placement,\n panelRef,\n inputRef,\n query,\n setQuery,\n results,\n busy,\n failed,\n tooShort,\n active,\n setActive,\n closeToTrigger,\n } = core;\n // The phone gets a full-screen sheet instead of an anchored panel (live #200).\n // Same core, same results, same handlers — only the container differs, so the\n // two presentations cannot drift in what they offer.\n const isPhone = useMediaQuery(PHONE_QUERY, false);\n // Every row the keyboard can land on, the create row included — passed over, like a\n // disabled option, while a write lock holds it.\n const rows: readonly { disabled?: boolean }[] = showCreate\n ? [...results, { disabled: createLocked }]\n : results;\n const rowCount = rows.length;\n const optionId = (index: number) => `${listboxId}-option-${index}`;\n // The core opens on row 0 and knows nothing of `disabled`; the highlight is settled\n // HERE, derived, so it can never rest on a row that cannot be taken — whatever the\n // async list turned out to hold.\n const current = settleEnabled(rows, active);\n const activeId = current >= 0 ? optionId(current) : undefined;\n useActiveOptionScroll(activeId);\n // The consumers resolve their own props against the provider already; this is\n // for the loading row, which no consumer names, and for a caller that renders the\n // panel directly and leaves the two optional strings out.\n const labels = useKitLabels(\"combobox\", DEFAULT_COMBOBOX_LABELS);\n // Portalled to <body>, the panel leaves the subtree its `dir` came from — so the\n // direction is read off the trigger and put back on the panel below.\n const dir = useAnchorDir(core.triggerRef, core.open);\n\n // The WAI-ARIA APG's listbox keyboard, in full: Up/Down step, Home/End jump, Enter\n // commits, Tab leaves. Escape is the one key handled elsewhere — `useComboboxCore`\n // registers it on the document, so it answers wherever focus has ended up.\n const onKeyDown = (e: ReactKeyboardEvent) => {\n // Disabled rows are passed over (`stepEnabled`), and each step starts from the\n // SETTLED highlight, not the raw index, so the first Down from a disabled row 0\n // goes to the row after the one already shown as highlighted.\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n setActive(stepEnabled(rows, current, 1));\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n setActive(current < 0 ? -1 : stepEnabled(rows, current, -1));\n } else if (e.key === \"Home\") {\n e.preventDefault();\n setActive(stepEnabled(rows, -1, 1));\n } else if (e.key === \"End\") {\n e.preventDefault();\n setActive(stepEnabled(rows, rowCount, -1));\n } else if (e.key === \"Enter\") {\n e.preventDefault();\n if (current < 0) return;\n if (current < results.length) onChoose(results[current]);\n else if (showCreate && !createLocked) onCreate();\n } else if (e.key === \"Tab\") {\n // The panel is PORTALLED to <body>, so the browser's own Tab would move from\n // here to whatever follows the portal — i.e. off the end of the document. The\n // trade is one extra Tab (trigger, then onward) against never stranding focus\n // at the bottom of the page.\n e.preventDefault();\n closeToTrigger();\n }\n };\n\n // What the list holds, said in ONE place that is both on screen and a polite\n // live region. Focus stays in the search box, so the list changing under it was\n // silent — a reader typed and heard nothing back, and a failed lookup was the same\n // silence as a slow one. Outside the listbox, which may own only options.\n //\n // Three different empties, and only one of them is \"nothing matched\": a lookup\n // that failed must not claim there is nothing to find, and a query under\n // `minChars` was never asked. With rows showing, the count is for the reader only.\n const message: ReactNode =\n busy && results.length === 0 ? (\n // The ellipsis is the picture; the words are for a reader, who otherwise met\n // an empty-looking list with a lone \"…\" in it — or, in most readers, nothing\n // at all, since punctuation alone is skipped.\n <>\n <span aria-hidden>…</span>\n <span className=\"sr-only\">{labels.loading}</span>\n </>\n ) : busy ? (\n // Loading with the LAST query's rows still up. This was `null`, so a refetch —\n // a new query, or a caller's `loading` while it reloads — looked exactly like a\n // finished list: rows that were about to be replaced, with nothing saying so.\n // A line of its own under the rows, in words, so it reads without the spinner.\n <span className=\"flex items-center gap-2\">\n <Spinner label={null} className=\"size-3.5 border\" />\n {labels.loading}\n </span>\n ) : results.length === 0 && !showCreate ? (\n failed ? (\n (loadErrorLabel ?? labels.loadError)\n ) : tooShort ? (\n labels.minChars(core.minChars)\n ) : (\n (emptyLabel ?? labels.noResults)\n )\n ) : null;\n // `relative` so the sr-only text has a local containing block (see\n // sr-only-containment.test).\n const announcement = (\n <div\n role=\"status\"\n aria-live=\"polite\"\n className={cn(\n \"relative\",\n message !== null && cn(\"py-2 text-sm\", isPhone ? \"px-4\" : \"px-3\"),\n failed ? \"text-[var(--danger)]\" : \"text-[var(--text-muted)]\",\n )}\n >\n {message ??\n (results.length > 0 && (\n <span className=\"sr-only\">{labels.resultCount(results.length)}</span>\n ))}\n </div>\n );\n\n if (!core.open || typeof document === \"undefined\") return null;\n\n const list = (\n <ul\n id={listboxId}\n role=\"listbox\"\n aria-multiselectable={multi}\n // The rows are provisional while a lookup is in flight — whether or not the\n // previous query's are still showing.\n aria-busy={busy || undefined}\n // It scrolls, and says so where jsdom can see it (see `CLIPS_ATTRIBUTE`): a\n // Tooltip in a row then portals out in a test exactly as it does in the\n // browser, instead of joining the option's accessible name (keksdose E8).\n {...{ [CLIPS_ATTRIBUTE]: \"\" }}\n className={cn(\"min-h-0 flex-1 overflow-y-auto py-1\", isPhone && \"flex-none\")}\n >\n {results.map((o, i) => {\n const selected = isSelected(o.value);\n // One heading per group rather than a grey suffix on every row (#136), and\n // the thing the native <select>'s <optgroup> used to give the account\n // picker for free (live #200). `results` keeps its source order, so a\n // boundary is simply \"different from the row above\".\n const startsGroup = o.group != null && o.group !== results[i - 1]?.group;\n return (\n // Keyed by group AND value: an option may deliberately appear twice —\n // Keksdose repeats recently-used categories in a \"Recent\" group at the\n // top (live #203) — and a bare value key would collide.\n <Fragment key={`${o.group ?? \"\"}|${String(o.value)}`}>\n {startsGroup && (\n <li\n role=\"presentation\"\n className={cn(\n \"font-semibold uppercase tracking-wide text-[var(--text-muted)]\",\n isPhone ? \"px-4 pb-1 pt-3 text-xs\" : \"px-3 pb-0.5 pt-2 text-[11px] first:pt-1\",\n )}\n >\n {o.group}\n </li>\n )}\n <li role=\"presentation\">\n <button\n type=\"button\"\n id={optionId(i)}\n role=\"option\"\n aria-selected={selected}\n aria-disabled={o.disabled || undefined}\n tabIndex={-1}\n onMouseDown={(e) => {\n e.preventDefault();\n if (!o.disabled) onChoose(o);\n }}\n onMouseEnter={() => {\n if (!o.disabled) setActive(i);\n }}\n className={cn(\n isPhone\n ? SHEET_ROW_CLASS\n : \"flex w-full items-center gap-2 px-3 py-1.5 text-start text-sm\",\n o.disabled\n ? DISABLED_ROW_CLASS\n : i === current && !isPhone\n ? \"bg-[var(--bg-active)]\"\n : !isPhone && \"hover:bg-[var(--bg-hover)]\",\n // After SHEET_ROW_CLASS, so its hover is the one cancelled.\n o.disabled && isPhone && DISABLED_ROW_CLASS,\n )}\n >\n {multi && (\n <span\n // The checkbox is a PICTURE of `aria-selected` above, so a reader\n // that met both would be told twice.\n aria-hidden\n className={cn(\n \"flex size-4 shrink-0 items-center justify-center rounded border\",\n selected\n ? \"border-[var(--bg-inverse)] bg-[var(--bg-inverse)] text-[var(--text-inverse)]\"\n : \"border-[var(--border-strong)] bg-[var(--bg-surface)]\",\n )}\n >\n {selected && <Check className=\"size-3\" />}\n </span>\n )}\n {o.icon && <span className=\"shrink-0\">{o.icon}</span>}\n <span className=\"min-w-0 flex-1\">\n <span className=\"block truncate text-[var(--text-primary)]\">{o.label}</span>\n {o.sublabel && (\n <span className=\"block truncate text-xs text-[var(--text-placeholder)]\">\n {o.sublabel}\n </span>\n )}\n </span>\n {!multi && selected && <Check className=\"size-4 shrink-0 text-[var(--brand)]\" />}\n </button>\n </li>\n </Fragment>\n );\n })}\n {showCreate && (\n <li role=\"presentation\">\n <button\n type=\"button\"\n id={optionId(results.length)}\n role=\"option\"\n // Never chosen — it is an action, and it disappears the moment it has\n // been taken. Whether the keyboard is ON it is `aria-activedescendant`'s\n // job to say.\n aria-selected={false}\n aria-disabled={createLocked || undefined}\n tabIndex={-1}\n onMouseDown={(e) => {\n e.preventDefault();\n if (!createLocked) onCreate();\n }}\n onMouseEnter={() => {\n if (!createLocked) setActive(results.length);\n }}\n className={cn(\n isPhone\n ? SHEET_ROW_CLASS\n : \"flex w-full items-center gap-2 px-3 py-1.5 text-start text-sm\",\n \"text-[var(--text-secondary)]\",\n createLocked\n ? DISABLED_ROW_CLASS\n : current === results.length && !isPhone\n ? \"bg-[var(--bg-active)]\"\n : !isPhone && \"hover:bg-[var(--bg-hover)]\",\n // After SHEET_ROW_CLASS, so its hover is the one cancelled.\n createLocked && isPhone && DISABLED_ROW_CLASS,\n )}\n >\n <Plus className=\"size-4 shrink-0\" />\n <span className=\"min-w-0 flex-1\">\n <span className=\"block truncate\">{createContent}</span>\n {createLocked && (\n <span className=\"block truncate text-xs text-[var(--text-placeholder)]\">\n {createDisabledReason}\n </span>\n )}\n </span>\n </button>\n </li>\n )}\n </ul>\n );\n\n if (isPhone) {\n return (\n <PickerSheet\n // First, so the sheet's own props below win: `rest` is typed as div\n // attributes, and the DOM's `title` is a tooltip string where the sheet's is\n // its heading — one name, two meanings, and the sheet's is the one the caller\n // asked for.\n {...rest}\n className={className}\n style={style}\n open\n onClose={() => core.setOpen(false)}\n title={sheetTitle}\n query={query}\n onQueryChange={setQuery}\n searchPlaceholder={searchPlaceholder ?? labels.search}\n inputRef={inputRef}\n closeLabel={closeLabel}\n >\n {/* eslint-disable-next-line jsx-a11y/no-static-element-interactions -- never focused\n itself: it catches the listbox keys bubbling from the sheet's search <input>,\n which holds focus while the list is up. */}\n <div onKeyDown={onKeyDown} className=\"relative\">\n {list}\n {announcement}\n </div>\n </PickerSheet>\n );\n }\n\n if (!rect) return null;\n // The panel hangs from the trigger's START edge: its left in a left-to-right form,\n // its right in a right-to-left one (it may be wider than the trigger, `minWidth`).\n // `clientWidth` rather than `innerWidth`, because a fixed box's `right` is measured\n // from the edge of the viewport inside any scrollbar.\n const inline =\n dir === \"rtl\"\n ? { right: (document.documentElement.clientWidth || window.innerWidth) - rect.right }\n : { left: rect.left };\n\n return createPortal(\n /* eslint-disable-next-line jsx-a11y/no-static-element-interactions -- never focused\n itself: it catches the listbox keys bubbling from the search <input> inside it,\n which holds focus while the panel is open. */\n <div\n // Spread FIRST: `onKeyDown` below is the listbox keyboard (Up/Down/Home/End/\n // Enter/Tab) and the placement is measured rather than chosen, so neither is a\n // caller's to replace by accident — while a `data-*` anchor or an\n // `aria-describedby` has nothing to collide with.\n {...rest}\n ref={panelRef}\n dir={dir}\n onKeyDown={onKeyDown}\n // `placement` keeps the panel inside the region actually on screen: on a phone\n // the search box below pulls up the keyboard, and a panel pinned under a\n // low trigger would otherwise sit entirely behind it (feedback #135).\n style={{\n ...style,\n position: \"fixed\",\n top: placement.top,\n ...inline,\n width: rect.width,\n minWidth: 220,\n maxHeight: placement.maxHeight,\n }}\n className={cn(\n \"z-50 flex flex-col rounded-md border border-[var(--border)] bg-[var(--bg-surface)] shadow-lg\",\n className,\n )}\n >\n <DropdownSearchHeader\n query={query}\n onQueryChange={setQuery}\n inputRef={inputRef}\n placeholder={searchPlaceholder ?? labels.search}\n // Focus is in this box while the list is up, so this is what has to name the\n // list and the row the arrows are on.\n listboxId={listboxId}\n activeId={activeId}\n />\n {/* One list, two containers: the desktop panel and the phone sheet render\n the same rows through the same handlers (live #200). */}\n {list}\n {announcement}\n </div>,\n document.body,\n );\n}\n"],"mappings":";AAqKI,SA+eE,UA/eF,KA+eE,YA/eF;AArKJ,SAAS,YAAAA,WAAU,WAAW,OAAO,SAAS,QAAQ,gBAAgB;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H,UAAU;AAAA,UACV,KAAK,UAAU;AAAA,UACf,GAAG;AAAA,UACH,OAAO,KAAK;AAAA,UACZ,UAAU;AAAA,UACV,WAAW,UAAU;AAAA,QACvB;AAAA,QACA,WAAW;AAAA,UACT;AAAA,UACA;AAAA,QACF;AAAA,QAEA;AAAA;AAAA,YAAC;AAAA;AAAA,cACC;AAAA,cACA,eAAe;AAAA,cACf;AAAA,cACA,aAAa,qBAAqB,OAAO;AAAA,cAGzC;AAAA,cACA;AAAA;AAAA,UACF;AAAA,UAGC;AAAA,UACA;AAAA;AAAA;AAAA,IACH;AAAA,IACA,SAAS;AAAA,EACX;AACF;","names":["Fragment"]}
|
|
@@ -29,10 +29,31 @@ interface ComboboxProps extends Omit<ComponentPropsWithoutRef<"div">, "id" | "on
|
|
|
29
29
|
* field, on the `<input>`'s `aria-describedby`, and implies `invalid` (lenkbank's
|
|
30
30
|
* scope fields, which moved here off `<Input list>` + `<datalist>`). */
|
|
31
31
|
error?: ReactNode;
|
|
32
|
+
/**
|
|
33
|
+
* Standing advice for the field — {@link Input}'s `hint`, so the combobox family
|
|
34
|
+
* reads like every other field (keksdose K4: the family had `error` and no `hint`, so
|
|
35
|
+
* the app's pickers carried their captions outside the component, attached to
|
|
36
|
+
* nothing). Plain TEXT is a caption under the field on the input's
|
|
37
|
+
* `aria-describedby`, before any error; a {@link FieldHint} "?" rides the label line,
|
|
38
|
+
* or with no label sits at the field's end edge, outside the box.
|
|
39
|
+
*/
|
|
40
|
+
hint?: ReactNode;
|
|
32
41
|
/** As `<input disabled>`: no focus, no list, the field's settled look. The chevron
|
|
33
42
|
* stops toggling with it — it is a mouse target the input's own `disabled` does
|
|
34
43
|
* not reach. */
|
|
35
44
|
disabled?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Why the value cannot be changed — {@link Button}'s `disabledReason`, for a field
|
|
47
|
+
* that SAVES itself (an inline editor whose blur writes). The input stays focusable
|
|
48
|
+
* and `aria-disabled`, is `readOnly`, opens no list and calls neither `onChange` nor
|
|
49
|
+
* `onSubmit`; the reason is in the kit {@link Tooltip} and on its `aria-describedby`.
|
|
50
|
+
* Wins over `disabled`. The family's lock (keksdose G2) — see {@link InlineEntityCombobox}.
|
|
51
|
+
*/
|
|
52
|
+
disabledReason?: ReactNode;
|
|
53
|
+
/** This field COMMITS. Under a locked {@link WriteLockProvider} it is locked the
|
|
54
|
+
* `disabledReason` way with the lock's reason; inside a form with its own Save, leave
|
|
55
|
+
* it off and put `commit` on the Save. No provider, or an unlocked one: no effect. */
|
|
56
|
+
commit?: boolean;
|
|
36
57
|
/** Heading an option belongs under. Supplying it makes this list read exactly
|
|
37
58
|
* like {@link InlineEntityCombobox}'s — one heading per group with its rows
|
|
38
59
|
* indented beneath — instead of a flat list (feedback #136 rework: the payee
|
|
@@ -96,7 +117,7 @@ interface ComboboxProps extends Omit<ComponentPropsWithoutRef<"div">, "id" | "on
|
|
|
96
117
|
* visually and behaviourally consistent with the other dropdowns (feedback
|
|
97
118
|
* #230 — the payee field looked/behaved differently from every other select).
|
|
98
119
|
*/
|
|
99
|
-
declare function Combobox(
|
|
120
|
+
declare function Combobox(props: ComboboxProps): react.JSX.Element;
|
|
100
121
|
/** `id` is the INPUT's and `onChange` is the field's — see {@link ComboboxProps}
|
|
101
122
|
* for why the div's spellings of them are omitted. */
|
|
102
123
|
interface InlineEntityComboboxProps<V extends string | number, C extends ComboClearValue = null> extends Omit<ComponentPropsWithoutRef<"div">, "id" | "onChange"> {
|
|
@@ -106,6 +127,8 @@ interface InlineEntityComboboxProps<V extends string | number, C extends ComboCl
|
|
|
106
127
|
invalid?: boolean;
|
|
107
128
|
/** What is wrong with the value — see {@link Combobox}'s `error`. */
|
|
108
129
|
error?: ReactNode;
|
|
130
|
+
/** Standing advice — see {@link Combobox}'s `hint` (keksdose K4). */
|
|
131
|
+
hint?: ReactNode;
|
|
109
132
|
/** A picked/typed option emits its id; emptying the field, or the "×", emits
|
|
110
133
|
* `clearValue`. */
|
|
111
134
|
onChange: (v: V | C) => void;
|
|
@@ -141,6 +164,72 @@ interface InlineEntityComboboxProps<V extends string | number, C extends ComboCl
|
|
|
141
164
|
* affordance both shells share, and it clears without opening anything. */
|
|
142
165
|
clearable?: boolean;
|
|
143
166
|
clearLabel?: string;
|
|
167
|
+
/**
|
|
168
|
+
* Why the choice cannot be changed — {@link Button}'s `disabledReason`, for a picker
|
|
169
|
+
* that SAVES on change. keksdose G2: the statement review's account picker IS the
|
|
170
|
+
* write (picking re-runs the duplicate check on the server), and on the read-only demo
|
|
171
|
+
* the app wrapped it in a hand-made Tooltip over a native `disabled` — out of the tab
|
|
172
|
+
* order, so the reason never reached a keyboard.
|
|
173
|
+
*
|
|
174
|
+
* With a reason the input stays focusable and `aria-disabled`, is `readOnly` (the
|
|
175
|
+
* settled grey), opens no list or sheet, offers no clear "×", and no pick, typed
|
|
176
|
+
* label or clear reaches `onChange`; the reason is in the kit {@link Tooltip} and on
|
|
177
|
+
* the input's `aria-describedby`. Wins over `disabled`. Use it CONTROLLED, as the
|
|
178
|
+
* component always is: the shown label is `value`'s.
|
|
179
|
+
*/
|
|
180
|
+
disabledReason?: ReactNode;
|
|
181
|
+
/**
|
|
182
|
+
* This picker COMMITS — choosing saves. Under a locked {@link WriteLockProvider} it is
|
|
183
|
+
* locked the `disabledReason` way with the lock's reason (which wins over its own).
|
|
184
|
+
* A picker inside a form with its own Save stays editable under the lock — leave this
|
|
185
|
+
* off there and put `commit` on the Save. No provider, or an unlocked one: no effect.
|
|
186
|
+
*/
|
|
187
|
+
commit?: boolean;
|
|
188
|
+
/**
|
|
189
|
+
* A last row that makes a new record from what was typed — keksdose G9, whose "Create
|
|
190
|
+
* cash account" had to become a separate button because this picker had no such row.
|
|
191
|
+
*
|
|
192
|
+
* Shown while the typed query is non-empty and names no option exactly
|
|
193
|
+
* (case-insensitive — an exact hit is a record the list already shows), worded
|
|
194
|
+
* `createLabel(query)`, default `combobox.create`: "Create “{query}”". The arrow keys
|
|
195
|
+
* reach it like an option; Enter or a click calls `onCreate(query)` and closes the
|
|
196
|
+
* list. Making the record, and then passing its id as `value`, is the caller's: the
|
|
197
|
+
* field shows the old selection until it does.
|
|
198
|
+
*
|
|
199
|
+
* The same rule as {@link EntityCombobox}'s `onCreate`, so the family agrees. It is a
|
|
200
|
+
* row of the LIST, not an option: it is never `aria-selected`, never matched by a
|
|
201
|
+
* typed label on blur, and never sorted among the records the way a sentinel option
|
|
202
|
+
* would be (the reason keksdose gave for the separate button).
|
|
203
|
+
*/
|
|
204
|
+
onCreate?: (query: string) => void;
|
|
205
|
+
/** The create row's words for a query. Default: `combobox.create` from the
|
|
206
|
+
* {@link UiKitProvider}, else English `Create “{query}”`. */
|
|
207
|
+
createLabel?: (query: string) => string;
|
|
208
|
+
/**
|
|
209
|
+
* Offer the create row with NOTHING typed too, worded as this — keksdose's "Create cash
|
|
210
|
+
* account", which mints an account under a default name and so needs no query.
|
|
211
|
+
* `onCreate` then receives `""`, and the caller supplies the name. Left out, the row
|
|
212
|
+
* needs a query.
|
|
213
|
+
*
|
|
214
|
+
* One string rather than a switch: a row with no query has nothing to quote, so the
|
|
215
|
+
* kit cannot word it — "Create “”" says nothing — and naming it is what turns it on.
|
|
216
|
+
* With both, one handler serves both rows:
|
|
217
|
+
*
|
|
218
|
+
* ```tsx
|
|
219
|
+
* onCreate={(name) => createCash(name || t("cash_account_default_name"))}
|
|
220
|
+
* createEmptyLabel={t("create_cash_account")}
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
createEmptyLabel?: string;
|
|
224
|
+
/**
|
|
225
|
+
* The create row WRITES while picking does not — keksdose dev#496: on the read-only
|
|
226
|
+
* demo choosing the cash account is draft state and stays live, minting one is a
|
|
227
|
+
* write. Under a locked {@link WriteLockProvider} the row stays in the list, dimmed and
|
|
228
|
+
* passed over by the arrows, with the lock's reason as its second line (a hover is the
|
|
229
|
+
* one explanation a phone cannot show), and `onCreate` is not called. Not needed with
|
|
230
|
+
* `commit`: a locked field opens no list at all.
|
|
231
|
+
*/
|
|
232
|
+
createCommit?: boolean;
|
|
144
233
|
}
|
|
145
234
|
/**
|
|
146
235
|
* The id-keyed sibling of {@link Combobox}: identical anatomy (a real text input
|
|
@@ -160,6 +249,6 @@ interface InlineEntityComboboxProps<V extends string | number, C extends ComboCl
|
|
|
160
249
|
* sheet that emptied it to show the full list would read as "the user cleared the
|
|
161
250
|
* field" the moment it closed.
|
|
162
251
|
*/
|
|
163
|
-
declare function InlineEntityCombobox<V extends string | number, C extends ComboClearValue = null>(
|
|
252
|
+
declare function InlineEntityCombobox<V extends string | number, C extends ComboClearValue = null>(props: InlineEntityComboboxProps<V, C>): react.JSX.Element;
|
|
164
253
|
|
|
165
254
|
export { Combobox, type ComboboxProps, InlineEntityCombobox, type InlineEntityComboboxProps };
|