@object-ui/fields 17.2.0 → 17.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. package/CHANGELOG.md +1533 -0
  2. package/README.md +1 -12
  3. package/dist/FieldEditWidget.d.ts +7 -1
  4. package/dist/currency.d.ts +46 -0
  5. package/dist/field-type-alias.d.ts +19 -1
  6. package/dist/index.cjs +5 -5
  7. package/dist/index.css +633 -0
  8. package/dist/index.d.ts +52 -12
  9. package/dist/index.js +5167 -4759
  10. package/dist/widgets/AddressField.d.ts +4 -12
  11. package/dist/widgets/AvatarField.d.ts +1 -1
  12. package/dist/widgets/CharacterCount.d.ts +56 -0
  13. package/dist/widgets/CheckboxesField.d.ts +1 -1
  14. package/dist/widgets/CodeField.d.ts +1 -1
  15. package/dist/widgets/ColorField.d.ts +1 -1
  16. package/dist/widgets/CurrencyField.d.ts +1 -1
  17. package/dist/widgets/EmailField.d.ts +1 -1
  18. package/dist/widgets/FileField.d.ts +1 -1
  19. package/dist/widgets/FilterConditionField.d.ts +1 -1
  20. package/dist/widgets/FullscreenFieldEditor.d.ts +45 -0
  21. package/dist/widgets/GeolocationField.d.ts +1 -1
  22. package/dist/widgets/GridField.d.ts +12 -2
  23. package/dist/widgets/ImageField.d.ts +1 -1
  24. package/dist/widgets/LocationField.d.ts +1 -1
  25. package/dist/widgets/LookupField.d.ts +1 -1
  26. package/dist/widgets/MultiSelectField.d.ts +1 -1
  27. package/dist/widgets/ObjectField.d.ts +1 -1
  28. package/dist/widgets/ObjectRefField.d.ts +1 -1
  29. package/dist/widgets/OptionsEmptyState.d.ts +59 -0
  30. package/dist/widgets/PercentField.d.ts +1 -1
  31. package/dist/widgets/PhoneField.d.ts +1 -1
  32. package/dist/widgets/QRCodeField.d.ts +1 -1
  33. package/dist/widgets/RadioField.d.ts +1 -1
  34. package/dist/widgets/RatingField.d.ts +1 -1
  35. package/dist/widgets/RecipientPickerField.d.ts +1 -1
  36. package/dist/widgets/RecordPickerDialog.d.ts +49 -7
  37. package/dist/widgets/RichTextField.d.ts +19 -1
  38. package/dist/widgets/SelectField.d.ts +25 -5
  39. package/dist/widgets/TagsField.d.ts +1 -1
  40. package/dist/widgets/TextAreaField.d.ts +44 -5
  41. package/dist/widgets/UrlField.d.ts +1 -1
  42. package/dist/widgets/address-format.d.ts +68 -0
  43. package/dist/widgets/file-size-guard.d.ts +41 -0
  44. package/dist/widgets/nativeDateValue.d.ts +37 -0
  45. package/dist/widgets/toDomProps.d.ts +111 -0
  46. package/dist/widgets/toHostGroupProps.d.ts +91 -0
  47. package/dist/widgets/types.d.ts +128 -33
  48. package/dist/widgets/useRecordQuery.d.ts +7 -1
  49. package/dist/withFieldCarrier.d.ts +56 -0
  50. package/package.json +20 -16
  51. package/src/FieldEditWidget.tsx +17 -1
  52. package/src/__tests__/AddressCellRenderer.test.tsx +166 -0
  53. package/src/__tests__/CurrencyField.minorUnits.test.tsx +191 -0
  54. package/src/__tests__/CurrencyField.symbol.test.tsx +198 -0
  55. package/src/__tests__/DateCellRenderer.test.tsx +9 -0
  56. package/src/__tests__/NumberCellRenderer.grouping.test.tsx +146 -0
  57. package/src/__tests__/PercentCellRenderer.locale.test.tsx +152 -0
  58. package/src/__tests__/PercentCellRenderer.test.tsx +115 -0
  59. package/src/__tests__/boolean-label-association-e2e.test.tsx +298 -0
  60. package/src/__tests__/capability-multiselect-retired.test.ts +109 -0
  61. package/src/__tests__/cell-truncation.test.tsx +96 -0
  62. package/src/__tests__/composite-group-label-e2e.test.tsx +436 -0
  63. package/src/__tests__/composite-group-label-readonly-e2e.test.tsx +403 -0
  64. package/src/__tests__/date-formatter-residue-4272.test.ts +120 -0
  65. package/src/__tests__/date-locale-channel.test.tsx +305 -0
  66. package/src/__tests__/field-carrier-sdui.test.tsx +169 -0
  67. package/src/__tests__/formatCurrency.centsDigit.test.tsx +158 -0
  68. package/src/__tests__/formatCurrency.minorUnits.test.tsx +221 -0
  69. package/src/__tests__/group-labelling-declaration.test.ts +148 -0
  70. package/src/__tests__/lookupCellRecordLink.test.tsx +171 -0
  71. package/src/__tests__/percent-cell-vs-measure-4576.test.ts +115 -0
  72. package/src/__tests__/percent-formatter-locale-4553.test.ts +147 -0
  73. package/src/__tests__/percent-tie-halfup-4590.test.ts +224 -0
  74. package/src/__tests__/select-label-association-e2e.test.tsx +199 -0
  75. package/src/__tests__/spec-symbol-batch7.test.ts +29 -15
  76. package/src/__tests__/validation-feedback.test.tsx +22 -13
  77. package/src/__tests__/widget-aria-invalid-e2e.test.tsx +265 -0
  78. package/src/__tests__/widget-aria-invalid-registry-e2e.test.tsx +338 -0
  79. package/src/__tests__/widget-dom-leak-e2e.test.tsx +357 -0
  80. package/src/__tests__/widget-props-contract.test.tsx +22 -9
  81. package/src/complex-widgets.test.tsx +22 -6
  82. package/src/currency.ts +130 -0
  83. package/src/datetime-widgets.test.tsx +94 -2
  84. package/src/field-type-alias.multiple.test.ts +81 -0
  85. package/src/field-type-alias.ts +58 -2
  86. package/src/index.css +44 -0
  87. package/src/index.tsx +558 -268
  88. package/src/standard-widgets.test.tsx +8 -1
  89. package/src/widgets/AddressField.postalCode.test.tsx +257 -0
  90. package/src/widgets/AddressField.tsx +107 -38
  91. package/src/widgets/AddressField.uniqueIds.test.tsx +93 -0
  92. package/src/widgets/AvatarField.tsx +9 -2
  93. package/src/widgets/BooleanField.tsx +44 -10
  94. package/src/widgets/CapabilityMultiSelectField.tsx +17 -5
  95. package/src/widgets/CharacterCount.tsx +263 -0
  96. package/src/widgets/CheckboxesField.tsx +66 -16
  97. package/src/widgets/CodeField.tsx +9 -2
  98. package/src/widgets/ColorField.tsx +11 -2
  99. package/src/widgets/CurrencyField.tsx +60 -19
  100. package/src/widgets/DateField.tsx +13 -4
  101. package/src/widgets/DateTimeField.tsx +14 -5
  102. package/src/widgets/EmailField.tsx +5 -5
  103. package/src/widgets/FileField.tsx +39 -11
  104. package/src/widgets/FilterConditionField.tsx +11 -0
  105. package/src/widgets/FormulaField.tsx +7 -2
  106. package/src/widgets/FullscreenFieldEditor.tsx +60 -0
  107. package/src/widgets/GeolocationField.tsx +49 -8
  108. package/src/widgets/GeolocationField.uniqueIds.test.tsx +88 -0
  109. package/src/widgets/GridField.test.tsx +226 -0
  110. package/src/widgets/GridField.tsx +115 -11
  111. package/src/widgets/ImageField.maxSize.test.tsx +154 -0
  112. package/src/widgets/ImageField.tsx +63 -6
  113. package/src/widgets/LocationField.tsx +9 -2
  114. package/src/widgets/LookupField.gateHintLabel.test.tsx +135 -0
  115. package/src/widgets/LookupField.hydration.test.tsx +1 -1
  116. package/src/widgets/LookupField.tsx +49 -10
  117. package/src/widgets/MasterDetailField.tsx +1 -1
  118. package/src/widgets/MultiSelectField.tsx +86 -16
  119. package/src/widgets/NumberField.tsx +3 -3
  120. package/src/widgets/ObjectField.tsx +17 -8
  121. package/src/widgets/ObjectRefField.tsx +10 -0
  122. package/src/widgets/OptionsEmptyState.no-provider.test.tsx +88 -0
  123. package/src/widgets/OptionsEmptyState.test.tsx +169 -0
  124. package/src/widgets/OptionsEmptyState.tsx +99 -0
  125. package/src/widgets/PasswordField.tsx +3 -3
  126. package/src/widgets/PeoplePicker.tsx +7 -1
  127. package/src/widgets/PercentField.tsx +5 -4
  128. package/src/widgets/PhoneField.tsx +5 -5
  129. package/src/widgets/QRCodeField.tsx +9 -2
  130. package/src/widgets/RadioField.tsx +58 -16
  131. package/src/widgets/RatingField.tsx +32 -4
  132. package/src/widgets/RecipientPickerField.tsx +18 -0
  133. package/src/widgets/RecordPickerDialog.baseFilterShapes.test.tsx +191 -0
  134. package/src/widgets/RecordPickerDialog.dateLocale.test.tsx +124 -0
  135. package/src/widgets/RecordPickerDialog.filterOptions.test.tsx +611 -0
  136. package/src/widgets/RecordPickerDialog.selectLabel.test.tsx +112 -0
  137. package/src/widgets/RecordPickerDialog.tsx +235 -21
  138. package/src/widgets/RichTextField.tsx +151 -24
  139. package/src/widgets/SelectField.tsx +84 -22
  140. package/src/widgets/SliderField.tsx +1 -1
  141. package/src/widgets/SummaryField.tsx +1 -1
  142. package/src/widgets/TagsField.placeholder.no-provider.test.tsx +68 -0
  143. package/src/widgets/TagsField.placeholder.test.tsx +95 -0
  144. package/src/widgets/TagsField.tsx +23 -2
  145. package/src/widgets/TextAreaField.tsx +171 -93
  146. package/src/widgets/TextField.tsx +3 -3
  147. package/src/widgets/TimeField.tsx +2 -2
  148. package/src/widgets/UrlField.tsx +5 -5
  149. package/src/widgets/UserField.tsx +4 -3
  150. package/src/widgets/VectorField.tsx +1 -1
  151. package/src/widgets/__tests__/FilterConditionField.operators.test.ts +25 -1
  152. package/src/widgets/__tests__/FullscreenFieldEditor.i18n.test.tsx +248 -0
  153. package/src/widgets/__tests__/FullscreenFieldEditor.no-provider.test.tsx +116 -0
  154. package/src/widgets/__tests__/RichTextField.fullscreenDisabled.test.tsx +244 -0
  155. package/src/widgets/__tests__/RichTextField.mobileFullscreen.test.tsx +195 -0
  156. package/src/widgets/__tests__/TextAreaField.characterCount.announcements.test.tsx +417 -0
  157. package/src/widgets/__tests__/TextAreaField.characterCount.i18n.test.tsx +287 -0
  158. package/src/widgets/__tests__/TextAreaField.characterCount.no-provider.test.tsx +160 -0
  159. package/src/widgets/__tests__/TextAreaField.fullscreenCharacterCount.i18n.test.tsx +161 -0
  160. package/src/widgets/__tests__/TextAreaField.fullscreenCharacterCount.test.tsx +346 -0
  161. package/src/widgets/__tests__/TextAreaField.fullscreenDisabled.test.tsx +246 -0
  162. package/src/widgets/__tests__/TextAreaField.mobileFullscreen.test.tsx +175 -0
  163. package/src/widgets/address-format.ts +120 -0
  164. package/src/widgets/file-size-guard.ts +55 -0
  165. package/src/widgets/nativeDateValue.test.ts +115 -0
  166. package/src/widgets/nativeDateValue.ts +112 -0
  167. package/src/widgets/optionWidgets.gatedOptions.test.tsx +267 -0
  168. package/src/widgets/optionWidgets.unconfiguredOptions.test.tsx +150 -0
  169. package/src/widgets/toDomProps.ts +204 -0
  170. package/src/widgets/toHostGroupProps.ts +102 -0
  171. package/src/widgets/types.ts +135 -35
  172. package/src/widgets/useFieldTranslation.ts +46 -4
  173. package/src/widgets/useRecordQuery.ts +30 -3
  174. package/src/withFieldCarrier.tsx +75 -0
  175. package/dist/FieldEditWidget.test.d.ts +0 -8
  176. package/dist/__tests__/DateCellRenderer.test.d.ts +0 -0
  177. package/dist/__tests__/NumberCellRenderer.test.d.ts +0 -0
  178. package/dist/__tests__/lookupCellDisplayField.test.d.ts +0 -0
  179. package/dist/__tests__/lookupCellDisplayName.test.d.ts +0 -0
  180. package/dist/__tests__/lookupCellReferenceKey.test.d.ts +0 -0
  181. package/dist/__tests__/registry-collision.test.d.ts +0 -0
  182. package/dist/__tests__/resolveFieldCurrency.test.d.ts +0 -1
  183. package/dist/__tests__/spec-symbol-batch7.test.d.ts +0 -8
  184. package/dist/__tests__/validation-feedback.test.d.ts +0 -0
  185. package/dist/__tests__/widget-props-contract.test.d.ts +0 -8
  186. package/dist/coerce-safe-value.test.d.ts +0 -1
  187. package/dist/complex-widgets.test.d.ts +0 -1
  188. package/dist/datetime-widgets.test.d.ts +0 -1
  189. package/dist/field-type-coverage.test.d.ts +0 -1
  190. package/dist/standard-widgets.test.d.ts +0 -0
  191. package/dist/widgets/CapabilityMultiSelectField.test.d.ts +0 -0
  192. package/dist/widgets/CheckboxesField.cascade.test.d.ts +0 -0
  193. package/dist/widgets/GridField.test.d.ts +0 -1
  194. package/dist/widgets/ImageLightbox.test.d.ts +0 -1
  195. package/dist/widgets/LookupField.dependsOn.test.d.ts +0 -8
  196. package/dist/widgets/LookupField.hydration.test.d.ts +0 -1
  197. package/dist/widgets/LookupField.idField.test.d.ts +0 -1
  198. package/dist/widgets/MultiSelectField.cascade.test.d.ts +0 -0
  199. package/dist/widgets/PeoplePicker.test.d.ts +0 -8
  200. package/dist/widgets/PeoplePickerComponents.test.d.ts +0 -8
  201. package/dist/widgets/RadioField.cascade.test.d.ts +0 -0
  202. package/dist/widgets/RecipientPickerField.test.d.ts +0 -0
  203. package/dist/widgets/SelectField.cascade.test.d.ts +0 -0
  204. package/dist/widgets/UserFieldPicker.test.d.ts +0 -8
  205. package/dist/widgets/__tests__/FilterConditionField.matchAll.test.d.ts +0 -8
  206. package/dist/widgets/__tests__/FilterConditionField.operators.test.d.ts +0 -8
  207. package/dist/widgets/deriveLookupColumns.test.d.ts +0 -1
  208. package/dist/widgets/file-value.test.d.ts +0 -1
  209. package/dist/widgets/personDisplay.test.d.ts +0 -8
  210. package/dist/widgets/recentLookups.test.d.ts +0 -1
  211. package/dist/widgets/useRecordQuery.test.d.ts +0 -8
  212. package/dist/widgets/useUploadingSignal.test.d.ts +0 -1
@@ -1,52 +1,86 @@
1
1
  import React, { useId } from 'react';
2
2
  import { Switch, Checkbox, Label } from '@object-ui/components';
3
3
  import { FieldWidgetComponentProps } from './types';
4
+ import { toDomProps } from './toDomProps';
4
5
 
5
6
  /**
6
7
  * BooleanField - Toggle input supporting switch and checkbox variants
7
8
  * Renders as Switch or Checkbox based on field widget configuration
8
9
  */
9
10
  export function BooleanField({ value, onChange, field, readonly, ...props }: FieldWidgetComponentProps<boolean>) {
10
- const config = (field || (props as any).schema) as any;
11
+ const config = field as any;
11
12
  // Use simple type assertion for arbitrary custom properties not in BaseFieldMetadata
12
13
  const widget = config?.widget;
13
14
  // Generate unique ID using React's useId hook - must be before early returns (rules of hooks)
14
15
  const generatedId = useId();
15
- const id = config?.name || generatedId;
16
+ /**
17
+ * The HOST owns the control's id (objectui#3952).
18
+ *
19
+ * `<FormControl>` is a Radix `Slot` that hands its child the id its
20
+ * `<FormLabel htmlFor>` already points at (`_r_N_-form-item`). This widget
21
+ * used to REPLACE it with the field name, so the form's visible label
22
+ * referenced an id no element carried: `label for="_r_3_-form-item"` against
23
+ * `all ids in form = ["notifications"]`. Clicking the label — the normal
24
+ * affordance for a switch/checkbox row — toggled nothing, on every generated
25
+ * form in every app.
26
+ *
27
+ * `id` is a DECLARED key of the widget contract (`FieldWidgetDomProps`) and
28
+ * `toDomProps` forwards it, so honouring it here is the contract's own
29
+ * direction: the fix belongs at the consumer that discarded a delivered
30
+ * value, not in the form renderer (AGENTS.md #0.1).
31
+ *
32
+ * The fallback chain stays for the STANDALONE hosts that hand down no id —
33
+ * `FieldEditWidget` (the grid's inline cell editor) and a bare SDUI node.
34
+ */
35
+ const hostId = props.id;
36
+ const id = hostId || config?.name || generatedId;
16
37
  const label = config?.label || 'Checkbox';
38
+ /**
39
+ * A host that supplies the id is a host that renders its own label for it
40
+ * (that is what the id is FOR), so the widget's `sr-only` label would be the
41
+ * second copy of one name — the other half of #3952, and why a naive
42
+ * `getByText(label)` on a boolean field returned two nodes.
43
+ *
44
+ * Standalone it is the control's ONLY accessible name (`FieldEditWidget`
45
+ * renders no label of its own), so there it stays. Deliberately keyed on the
46
+ * host id rather than on `config.label`: inside a form the naming is the
47
+ * host's job for EVERY widget — a text field in a label-less form row is
48
+ * equally unnamed — and the generic `'Checkbox'` fallback emitted there was
49
+ * an actively WRONG accessible name, not a safety net.
50
+ */
51
+ const emitOwnLabel = !hostId;
17
52
 
18
53
  if (readonly) {
19
54
  return <span className="text-sm">{value ? 'Yes' : 'No'}</span>;
20
55
  }
21
56
 
22
- // Filter out non-DOM props
23
- const { inputType, ...domProps } = props as any;
57
+ const domProps = toDomProps(props);
24
58
 
25
59
  if (widget === 'checkbox') {
26
60
  return (
27
61
  <div className="flex items-center space-x-2">
28
- <Checkbox
62
+ <Checkbox
29
63
  {...domProps}
30
64
  id={id}
31
65
  checked={!!value}
32
66
  onCheckedChange={(checked) => onChange(!!checked)}
33
67
  disabled={readonly || domProps.disabled}
34
68
  />
35
- <Label htmlFor={id} className="sr-only">{label}</Label>
69
+ {emitOwnLabel && <Label htmlFor={id} className="sr-only">{label}</Label>}
36
70
  </div>
37
71
  )
38
72
  }
39
73
 
40
74
  return (
41
75
  <div className="flex items-center space-x-2">
42
- <Switch
76
+ <Switch
43
77
  {...domProps}
44
- id={id}
45
- checked={!!value}
78
+ id={id}
79
+ checked={!!value}
46
80
  onCheckedChange={onChange}
47
81
  disabled={readonly || domProps.disabled}
48
82
  />
49
- <Label htmlFor={id} className="sr-only">{label}</Label>
83
+ {emitOwnLabel && <Label htmlFor={id} className="sr-only">{label}</Label>}
50
84
  </div>
51
85
  );
52
86
  }
@@ -18,9 +18,18 @@ import { useFieldTranslation } from './useFieldTranslation';
18
18
  * labelled, with the capability description on hover — while round-tripping the
19
19
  * stored value **byte-for-byte** as a JSON string of names.
20
20
  *
21
- * Reached via the field `widget: 'capability-multiselect'` hint (stamped onto
22
- * the object metadata in MetadataProvider), registered in the field registry as
23
- * `field:capability-multiselect`.
21
+ * ## Not a registry field widget (objectui#3308)
22
+ *
23
+ * This is a plain component, imported directly by its host — Studio's
24
+ * `PermissionMatrixEditor` (`packages/app-shell`), which is where ADR-0056 P2
25
+ * put the capability editor. It is deliberately NOT reachable through the field
26
+ * registry, and `widget: 'capability-multiselect'` is a **retired** hint: the
27
+ * key only ever existed on the docs-site-only `registerFields()` path, nothing
28
+ * ever stamped the hint (ADR-0056 P1 stamps `permission-facet-link` on all six
29
+ * `sys_permission_set` facets), and it was removed under ADR-0049
30
+ * enforce-or-remove. Do not re-register it without re-deciding ADR-0056 P2 —
31
+ * a field carrying that hint now degrades to its declared `type` renderer,
32
+ * which is the defined behavior for an unregistered widget.
24
33
  */
25
34
 
26
35
  interface Capability {
@@ -98,8 +107,11 @@ export function CapabilityMultiSelectField({
98
107
  const selected = React.useMemo(() => parseCapabilityNames(value), [value]);
99
108
 
100
109
  // Load the live capability registry (active only). Mirrors LookupField's
101
- // context-dataSource access — createFieldRenderer does not forward the
102
- // dataSource prop, so the SchemaRenderer context is the reliable source.
110
+ // context-dataSource access: no registration path forwards a `dataSource`
111
+ // prop to a field widget, so the SchemaRenderer context is the reliable
112
+ // source. (The absent forwarder named here used to be the docs-demo
113
+ // `createFieldRenderer`, removed in objectui#3910 — the conclusion is
114
+ // unchanged and now holds for the only remaining path.)
103
115
  React.useEffect(() => {
104
116
  if (!dataSource || typeof (dataSource as any).find !== 'function') return;
105
117
  let cancelled = false;
@@ -0,0 +1,263 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+
9
+ import React, { useEffect, useState } from 'react';
10
+ import { useFieldTranslation } from './useFieldTranslation';
11
+
12
+ /**
13
+ * The character counter a capped long-text field renders, in the GOV.UK
14
+ * character-count shape — extracted from `TextAreaField` so that widget's TWO
15
+ * editing surfaces (the inline textarea and the fullscreen dialog) render the
16
+ * SAME counting UI instead of two hand-written copies (objectui#3417).
17
+ *
18
+ * ## Why this is shared rather than copied
19
+ *
20
+ * objectui#3408 gave the inline counter three nodes — decorative digits, an
21
+ * accessible description, a gated status region. The fullscreen dialog's
22
+ * counter, passed to `FullscreenFieldEditor` as a `footer`, stayed what it had
23
+ * always been: a bare `{n}/{max}` `span` with no accessible name, no
24
+ * `aria-describedby` association with the dialog's textarea, and nothing
25
+ * `aria-live`. Same field, same cap, same user — and a screen reader in the
26
+ * fullscreen dialog got nothing at all, while browse mode read "5 slash 500".
27
+ *
28
+ * That is the failure mode this package keeps paying for (objectui#3301: the
29
+ * fullscreen flag reached `RichTextField` for as long as the feature existed
30
+ * and that widget never read it). A second hand-written copy of a counting UI
31
+ * is the same failure with an extra step: it drifts, and nothing reports the
32
+ * drift. So the counter has ONE implementation and each surface renders it.
33
+ *
34
+ * ## The three nodes, and why the third is a prop
35
+ *
36
+ * 1. the visible `{n}/{max}` digits, `aria-hidden` — a glance affordance;
37
+ * 2. a visually-hidden DESCRIPTION carrying the translated sentence. The host
38
+ * owns {@link CharacterCountProps.descriptionId} and MUST name it in the
39
+ * edited control's `aria-describedby`, which is what makes the sentence
40
+ * reachable on focus rather than only in browse mode;
41
+ * 3. a visually-hidden `aria-live="polite"` STATUS region, silent until the
42
+ * value is inside the last 10% / 20 characters of the cap and updated only
43
+ * after the typist pauses.
44
+ *
45
+ * Node 3 is opt-in per surface ({@link CharacterCountProps.announceNearLimit}),
46
+ * required rather than defaulted, because "should this surface interrupt the
47
+ * user while they type?" is a real decision and neither answer should be
48
+ * reached by leaving a prop off. The fullscreen dialog answers no: it is a
49
+ * modal the user opened deliberately to write at length, the description
50
+ * already tells them the cap on focus, and the dialog's own textarea carries
51
+ * the same native `maxLength` stop as the inline one. The inline surface
52
+ * answers yes, unchanged from objectui#3408.
53
+ */
54
+
55
+ /**
56
+ * How long the typist must pause before the counter's status region is allowed
57
+ * to change (objectui#3408). The GOV.UK Design System character-count component
58
+ * uses the same shape and the same order of magnitude.
59
+ *
60
+ * The number this replaces was effectively 0: the counter WAS the live region,
61
+ * so every keystroke re-rendered it and every re-render was an announcement.
62
+ * Measured on `origin/main`, zh session, `maxLength: 500`, typing a 52-character
63
+ * sentence one character at a time: 52 keystrokes produced 52 distinct
64
+ * announcements totalling 979 spoken characters — ~19x the text the user was
65
+ * trying to write, each one interrupting the screen reader's echo of what they
66
+ * had just typed.
67
+ */
68
+ const COUNTER_STATUS_DEBOUNCE_MS = 1000;
69
+
70
+ /** Announce inside the last 10% of the cap … */
71
+ const COUNTER_STATUS_REMAINING_RATIO = 0.1;
72
+ /** … or the last 20 characters — whichever the typist reaches FIRST. */
73
+ const COUNTER_STATUS_MIN_REMAINING = 20;
74
+
75
+ /**
76
+ * The remaining-character count at or below which the status region speaks.
77
+ *
78
+ * "10% remaining OR 20 characters remaining, whichever comes first" is a
79
+ * disjunction, and because `remaining` only ever counts DOWN as the user types,
80
+ * the branch that fires first is simply the LARGER of the two — hence `max`.
81
+ * A 500-character cap starts warning at 50 remaining; a 100-character cap at 20
82
+ * (10% of it would be 10, which the typist would reach later, not sooner).
83
+ *
84
+ * A cap smaller than {@link COUNTER_STATUS_MIN_REMAINING} is therefore "near
85
+ * the limit" from the first keystroke, which is correct: on a 10-character
86
+ * field every character genuinely is one of the last few. The debounce still
87
+ * bounds it to one announcement per pause.
88
+ */
89
+ function counterStatusThreshold(maxLength: number): number {
90
+ return Math.max(
91
+ Math.ceil(maxLength * COUNTER_STATUS_REMAINING_RATIO),
92
+ COUNTER_STATUS_MIN_REMAINING,
93
+ );
94
+ }
95
+
96
+ export interface CharacterCountProps {
97
+ /**
98
+ * Length of the text this surface is counting. The inline surface passes the
99
+ * committed value's length; the fullscreen dialog passes the DRAFT's, which
100
+ * is the number that is true of what the user is looking at.
101
+ */
102
+ length: number;
103
+ /**
104
+ * The declared cap. Callers render this component only when the field
105
+ * declares one, so it is non-optional here — a counter with no cap to count
106
+ * against has nothing to say and must not be mounted at all (an unconditional
107
+ * live region in every long-text field is the objectui#3408 defect back
108
+ * again).
109
+ */
110
+ maxLength: number;
111
+ /**
112
+ * The description node's `id`, minted by the host from `useId()`.
113
+ *
114
+ * The host MUST also name it in the edited control's `aria-describedby` —
115
+ * this component renders the sentence, only the host knows which element is
116
+ * being described, and a description nothing references is a node no screen
117
+ * reader will ever reach. That association is asserted from the OUTSIDE (the
118
+ * tests resolve `aria-describedby` and concatenate the referenced nodes' text,
119
+ * exactly as an assistive technology does) rather than trusted here.
120
+ *
121
+ * Two surfaces of one widget therefore need two ids: the dialog's draft and
122
+ * the inline value diverge the moment the user types in the dialog, so one
123
+ * shared id would point both controls at whichever sentence rendered last.
124
+ */
125
+ descriptionId: string;
126
+ /**
127
+ * Render node 3, the threshold-gated debounced `aria-live` status region.
128
+ *
129
+ * Required on purpose — see the component doc above. `false` removes the
130
+ * region from the DOM entirely (not merely empties it), which is the only
131
+ * form of "no live region" a test can tell apart from "a live region that
132
+ * happens to be silent right now".
133
+ */
134
+ announceNearLimit: boolean;
135
+ /**
136
+ * Classes for the visible digits. Required because placement is entirely the
137
+ * surface's business — inline pins them to the textarea's bottom-right
138
+ * corner, the dialog lays them out as a footer item — and a default borrowed
139
+ * from either one would position the other wrongly while looking deliberate.
140
+ */
141
+ className: string;
142
+ /**
143
+ * `data-testid` for the visible digits, namespaced per surface
144
+ * (`textarea-character-count`, `textarea-fullscreen-character-count`) so a
145
+ * test that finds digits can say WHICH surface it found them on. Same
146
+ * convention, same reason, as `FullscreenFieldEditor`'s `testIdPrefix`.
147
+ */
148
+ testId: string;
149
+ }
150
+
151
+ export function CharacterCount({
152
+ length,
153
+ maxLength,
154
+ descriptionId,
155
+ announceNearLimit,
156
+ className,
157
+ testId,
158
+ }: CharacterCountProps) {
159
+ const { t } = useFieldTranslation();
160
+
161
+ /**
162
+ * The counter sentence as a DESCRIPTION (objectui#3408). Reached through the
163
+ * edited control's `aria-describedby`, so focusing it says "12 characters,
164
+ * 500 max" once and then shuts up. Before this the cap was announced only as
165
+ * a side effect of typing — focus told a screen reader user nothing at all
166
+ * that a sighted user could read off the corner of the box.
167
+ */
168
+ const description = t('fields.textarea.characterCount', { count: length, max: maxLength });
169
+
170
+ /**
171
+ * The near-limit warning, gated. Silent for the whole comfortable middle of
172
+ * the field — a count nobody is close to is not news — and phrased as what
173
+ * is LEFT rather than what has been typed, because that is the number the
174
+ * user is about to act on. Over-long values (a cap lowered after the record
175
+ * was saved) clamp to 0: the textarea's own `maxLength` blocks further
176
+ * input, so "0 left" is the true actionable state, and the description above
177
+ * still carries the honest `503 of 500`.
178
+ *
179
+ * Short-circuited by `announceNearLimit` rather than only hidden at render
180
+ * time, so a surface that renders no status region also schedules no timer —
181
+ * a debounce firing into a region that does not exist is a state update with
182
+ * no consumer, and in tests an `act()` warning with no cause.
183
+ */
184
+ const pendingStatus =
185
+ announceNearLimit && maxLength - length <= counterStatusThreshold(maxLength)
186
+ ? t('fields.textarea.charactersRemaining', { count: Math.max(maxLength - length, 0) })
187
+ : '';
188
+
189
+ /**
190
+ * The last sentence a PAUSE settled on. Only ever written by the timer —
191
+ * never cleared synchronously — so this effect adds no cascading render on
192
+ * the keystrokes it is busy staying quiet through
193
+ * (`react-hooks/set-state-in-effect`).
194
+ */
195
+ const [settledStatus, setSettledStatus] = useState('');
196
+
197
+ useEffect(() => {
198
+ if (!pendingStatus) return;
199
+ const timer = setTimeout(() => setSettledStatus(pendingStatus), COUNTER_STATUS_DEBOUNCE_MS);
200
+ // Every keystroke cancels the previous pending announcement, so a typist
201
+ // who never pauses is never interrupted. The dependency is the SENTENCE,
202
+ // not the length: re-typing back to the same count produces the same string
203
+ // and therefore no DOM change and no second announcement.
204
+ return () => clearTimeout(timer);
205
+ }, [pendingStatus]);
206
+
207
+ /**
208
+ * Speak the settled sentence only while it is still TRUE — i.e. while it is
209
+ * the one the current value would produce. Everything else renders empty,
210
+ * which costs no speech (emptying a live region announces nothing), and that
211
+ * is what makes leaving the warning band silent IMMEDIATELY rather than a
212
+ * second later.
213
+ *
214
+ * The obvious alternative, `pendingStatus ? settledStatus : ''`, is wrong in
215
+ * one specific way: delete back out of the band and type into it again, and
216
+ * the region re-announces the STALE count from before the excursion a full
217
+ * second before the timer corrects it. Announcing a wrong number is worse
218
+ * than announcing a right one twice, which is the bounded, sub-second,
219
+ * correct-content cost of the comparison below. Pinned by `never
220
+ * re-announces the STALE count when the user types back into the band`.
221
+ */
222
+ const status = settledStatus === pendingStatus ? pendingStatus : '';
223
+
224
+ return (
225
+ <>
226
+ {/*
227
+ The VISIBLE counter, and visible ONLY (objectui#3408). It used to be
228
+ three things at once: the digits a sighted user glances at, the carrier
229
+ of the translated sentence (objectui#3406), and the live region itself —
230
+ so the sentence was re-announced on every single keystroke. Split into
231
+ the three nodes here, this one is decorative: `aria-hidden` keeps a
232
+ screen reader from reading "5 slash 200" on top of the description that
233
+ says it properly.
234
+ */}
235
+ <div className={className} aria-hidden="true" data-testid={testId}>
236
+ {length}/{maxLength}
237
+ </div>
238
+
239
+ {/*
240
+ The DESCRIPTION. Referenced by the edited control's `aria-describedby`,
241
+ never announced on its own — a screen reader reads it when focus lands
242
+ on the control and not again. Visually hidden because the digits above
243
+ already say it to the eye.
244
+ */}
245
+ <span id={descriptionId} className="sr-only">
246
+ {description}
247
+ </span>
248
+
249
+ {/*
250
+ The STATUS region, on the surfaces that opted in. Rendered
251
+ unconditionally there and starting EMPTY on purpose: a live region has
252
+ to be in the DOM before its content changes or the first change is not
253
+ announced at all. `aria-atomic` so the whole sentence is spoken rather
254
+ than the digits that differ from last time.
255
+ */}
256
+ {announceNearLimit && (
257
+ <span className="sr-only" aria-live="polite" aria-atomic="true">
258
+ {status}
259
+ </span>
260
+ )}
261
+ </>
262
+ );
263
+ }
@@ -2,6 +2,9 @@ import React, { useId, useEffect } from 'react';
2
2
  import { Checkbox, Label, EmptyValue, Badge } from '@object-ui/components';
3
3
  import type { OptionLike } from '@object-ui/core';
4
4
  import { FieldWidgetComponentProps } from './types';
5
+ import { toDomProps } from './toDomProps';
6
+ import { toHostGroupProps } from './toHostGroupProps';
7
+ import { OptionsEmptyState } from './OptionsEmptyState';
5
8
  import { useCascadingOptions } from './useCascadingOptions';
6
9
 
7
10
  type Option = OptionLike;
@@ -24,14 +27,14 @@ export function CheckboxesField({
24
27
  field,
25
28
  readonly,
26
29
  className,
27
- schema,
28
30
  dependentValues,
29
31
  dependsOn: dependsOnProp,
30
- emptyHint: _emptyHint,
32
+ emptyHint,
31
33
  dataSource: _dataSource,
34
+ error,
32
35
  ...props
33
36
  }: FieldWidgetComponentProps<string[]>) {
34
- const config = (field || schema) as any;
37
+ const config = field as any;
35
38
  const rawOptions: Option[] = config?.options || [];
36
39
  const selected: string[] = Array.isArray(value) ? value : value == null ? [] : [value as unknown as string];
37
40
  const groupId = useId();
@@ -49,16 +52,36 @@ export function CheckboxesField({
49
52
  // per-element clear the multi-value case needs (cf. the scalar select/radio).
50
53
  useEffect(() => {
51
54
  if (readonly) return;
55
+ // Never configured → nothing to prune against; see `MultiSelectField`'s
56
+ // copy of this guard for the measured failure (objectui#4220).
57
+ if (rawOptions.length === 0) return;
58
+ // Gated → the authored list is withheld until the `dependsOn` parent is
59
+ // chosen, so the empty offered set is missing information, not a verdict on
60
+ // the stored value; clearing here fired on mount (objectui#4247). Same
61
+ // reasoning, at length, in `MultiSelectField`.
62
+ if (gated) return;
52
63
  if (selected.length === 0) return;
53
64
  const stillOffered = selected.filter((v) => options.some((o) => o.value === v));
54
65
  if (stillOffered.length !== selected.length) onChange(stillOffered);
55
66
  // eslint-disable-next-line react-hooks/exhaustive-deps
56
67
  }, [options, gated]);
57
68
 
69
+ // The host's group label has to be consumed on EVERY surface this widget can
70
+ // render, not only the editable one (objectui#3990): both branches below
71
+ // return before the editable container's `groupDomProps` spread, which is how
72
+ // a field-level `readonly: true` and a zero-option list ended up with a
73
+ // published label id and no consumer at all. See `toHostGroupProps`.
74
+ const hostGroupProps = toHostGroupProps(props);
75
+
58
76
  if (readonly) {
59
- if (selected.length === 0) return <EmptyValue />;
77
+ // The readonly display of a checkbox set is the set of CHECKED labels — a
78
+ // set of values, so the same `group` answer as the editable list.
79
+ // `EmptyValue` is that surface with nothing in it; its own `aria-label`
80
+ // ("No value") is outranked by `aria-labelledby` per accname, and on the
81
+ // `generic` role that span carries it was never exposed anyway.
82
+ if (selected.length === 0) return <EmptyValue {...hostGroupProps} />;
60
83
  return (
61
- <div className="flex flex-wrap gap-1">
84
+ <div {...hostGroupProps} className="flex flex-wrap gap-1">
62
85
  {selected.map((v) => {
63
86
  // Label from the raw set so a stored value hidden by `visibleWhen`
64
87
  // still renders its label rather than a bare id.
@@ -70,19 +93,21 @@ export function CheckboxesField({
70
93
  }
71
94
 
72
95
  // No offered options is unfillable — surface a legible state instead of an
73
- // empty checkbox list: a dependency-gated list prompts for its controlling
74
- // field; an unconfigured / fully-filtered list says so. Mirrors the select.
96
+ // empty checkbox list: the host's `emptyHint` when it computed one, else this
97
+ // widget's own translated copy. Shared with the select / multiselect / radio
98
+ // so the four cannot drift again (objectui#3231).
75
99
  if (options.length === 0) {
76
- const hint = gated
77
- ? `Select ${dependsOnFields.join(' / ')} first`
78
- : 'No options available';
79
100
  return (
80
- <div
81
- data-testid={fieldName ? `checkboxes-empty-${fieldName}` : undefined}
82
- className="flex min-h-9 w-full items-center rounded-md border border-input bg-muted/30 px-3 py-2 text-sm text-muted-foreground"
83
- >
84
- {hint}
85
- </div>
101
+ <OptionsEmptyState
102
+ emptyHint={emptyHint}
103
+ gated={gated}
104
+ dependsOnFields={dependsOnFields}
105
+ testId={fieldName ? `checkboxes-empty-${fieldName}` : undefined}
106
+ className="min-h-9"
107
+ // This box IS the field in this state, so it is what the host label
108
+ // names (objectui#3990).
109
+ hostGroupProps={hostGroupProps}
110
+ />
86
111
  );
87
112
  }
88
113
 
@@ -91,8 +116,32 @@ export function CheckboxesField({
91
116
  onChange(next);
92
117
  };
93
118
 
119
+ // DOM pass-through (objectui#3318): the container carries the form
120
+ // renderer's id / aria-describedby, but NOT its `aria-invalid` — a plain
121
+ // wrapper div is not where assistive tech reads the invalid state. That
122
+ // state goes onto every focusable checkbox below (`checkbox` is an
123
+ // aria-invalid-supporting role), computed from the published `error` slot
124
+ // (#3222). The per-item ids below stay authoritative for their labels.
125
+ // `name` is withheld too: it is only DOM-legal on form controls, and on
126
+ // this div it is exactly the leak #3291 sweeps for.
127
+ const {
128
+ 'aria-invalid': _hostAriaInvalid,
129
+ name: _domName,
130
+ ...groupDomProps
131
+ } = toDomProps(props);
132
+ // When the host associated its visible label with this container by IDREF
133
+ // (`aria-labelledby`, objectui#3961) the container IS the labelled group, so it
134
+ // answers with the matching role — without one, the name sits on a generic
135
+ // `div` and contributes nothing: `label for` pointing here was already inert
136
+ // (`HTMLLabelElement.control` is null for a div), which is the whole defect.
137
+ // Absent (standalone: the inline grid editor, a bare SDUI node) nothing is
138
+ // emitted and the markup is unchanged.
139
+ const isLabelledGroup = groupDomProps['aria-labelledby'] != null;
140
+
94
141
  return (
95
142
  <div
143
+ {...groupDomProps}
144
+ role={isLabelledGroup ? 'group' : undefined}
96
145
  className={className}
97
146
  data-testid={fieldName ? `checkboxes-${fieldName}` : undefined}
98
147
  >
@@ -108,6 +157,7 @@ export function CheckboxesField({
108
157
  checked={selected.includes(value)}
109
158
  onCheckedChange={(checked) => toggle(value, !!checked)}
110
159
  disabled={props.disabled}
160
+ aria-invalid={!!error}
111
161
  data-testid={`checkboxes-option-${value}`}
112
162
  />
113
163
  <Label htmlFor={id} className="font-normal">{opt.label}</Label>
@@ -1,14 +1,15 @@
1
1
  import React from 'react';
2
2
  import { Textarea, cn, EmptyValue } from '@object-ui/components';
3
3
  import { FieldWidgetComponentProps } from './types';
4
+ import { toDomProps } from './toDomProps';
4
5
 
5
6
  /**
6
7
  * Code field widget - provides a code editor with syntax highlighting
7
8
  * Uses a simple textarea with monospace font
8
9
  * For advanced code editing, use the @object-ui/plugin-editor component
9
10
  */
10
- export function CodeField({ value, onChange, field, readonly, ...props }: FieldWidgetComponentProps<string>) {
11
- const config = field || (props as any).schema;
11
+ export function CodeField({ value, onChange, field, readonly, error, ...props }: FieldWidgetComponentProps<string>) {
12
+ const config = field;
12
13
  // Get code-specific configuration from field metadata
13
14
  const language = (config as any)?.language ?? 'javascript';
14
15
 
@@ -22,6 +23,8 @@ export function CodeField({ value, onChange, field, readonly, ...props }: FieldW
22
23
 
23
24
  return (
24
25
  <Textarea
26
+ // DOM pass-through onto the real focusable control (objectui#3318).
27
+ {...toDomProps(props)}
25
28
  value={value || ''}
26
29
  onChange={(e) => onChange(e.target.value)}
27
30
  placeholder={config?.placeholder || `// Write ${language} code here...`}
@@ -29,6 +32,10 @@ export function CodeField({ value, onChange, field, readonly, ...props }: FieldW
29
32
  className={cn("font-mono text-sm", props.className)}
30
33
  rows={12}
31
34
  spellCheck={false}
35
+ // AFTER the spread so this widget's own computation wins: `error` is
36
+ // the published validation slot (#3222), `!!undefined` → explicit
37
+ // "false".
38
+ aria-invalid={!!error}
32
39
  />
33
40
  );
34
41
  }
@@ -1,13 +1,14 @@
1
1
  import React from 'react';
2
2
  import { Input, EmptyValue } from '@object-ui/components';
3
3
  import { FieldWidgetComponentProps } from './types';
4
+ import { toDomProps } from './toDomProps';
4
5
 
5
6
  /**
6
7
  * Color field widget - provides a color picker input
7
8
  * Supports hex color values (e.g., #ff0000)
8
9
  */
9
- export function ColorField({ value, onChange, field, readonly, ...props }: FieldWidgetComponentProps<string>) {
10
- const colorField = (field || (props as any).schema) as any;
10
+ export function ColorField({ value, onChange, field, readonly, error, ...props }: FieldWidgetComponentProps<string>) {
11
+ const colorField = field as any;
11
12
 
12
13
  if (readonly) {
13
14
  return (
@@ -29,8 +30,14 @@ export function ColorField({ value, onChange, field, readonly, ...props }: Field
29
30
  onChange={(e) => onChange(e.target.value)}
30
31
  disabled={readonly || props.disabled}
31
32
  className="w-10 h-10 rounded border border-input cursor-pointer"
33
+ // Both focusable halves of this widget announce the same validation
34
+ // state (objectui#3318).
35
+ aria-invalid={!!error}
32
36
  />
33
37
  <Input
38
+ // DOM pass-through onto the primary text control (objectui#3318): the
39
+ // whitelist spread carries the form renderer's id / aria-describedby.
40
+ {...toDomProps(props)}
34
41
  type="text"
35
42
  value={value || ''}
36
43
  onChange={(e) => onChange(e.target.value)}
@@ -38,6 +45,8 @@ export function ColorField({ value, onChange, field, readonly, ...props }: Field
38
45
  disabled={readonly || props.disabled}
39
46
  className={props.className}
40
47
  pattern="^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$"
48
+ // AFTER the spread so this widget's own computation wins (#3222).
49
+ aria-invalid={!!error}
41
50
  />
42
51
  </div>
43
52
  );