@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.
- package/CHANGELOG.md +1533 -0
- package/README.md +1 -12
- package/dist/FieldEditWidget.d.ts +7 -1
- package/dist/currency.d.ts +46 -0
- package/dist/field-type-alias.d.ts +19 -1
- package/dist/index.cjs +5 -5
- package/dist/index.css +633 -0
- package/dist/index.d.ts +52 -12
- package/dist/index.js +5167 -4759
- package/dist/widgets/AddressField.d.ts +4 -12
- package/dist/widgets/AvatarField.d.ts +1 -1
- package/dist/widgets/CharacterCount.d.ts +56 -0
- package/dist/widgets/CheckboxesField.d.ts +1 -1
- package/dist/widgets/CodeField.d.ts +1 -1
- package/dist/widgets/ColorField.d.ts +1 -1
- package/dist/widgets/CurrencyField.d.ts +1 -1
- package/dist/widgets/EmailField.d.ts +1 -1
- package/dist/widgets/FileField.d.ts +1 -1
- package/dist/widgets/FilterConditionField.d.ts +1 -1
- package/dist/widgets/FullscreenFieldEditor.d.ts +45 -0
- package/dist/widgets/GeolocationField.d.ts +1 -1
- package/dist/widgets/GridField.d.ts +12 -2
- package/dist/widgets/ImageField.d.ts +1 -1
- package/dist/widgets/LocationField.d.ts +1 -1
- package/dist/widgets/LookupField.d.ts +1 -1
- package/dist/widgets/MultiSelectField.d.ts +1 -1
- package/dist/widgets/ObjectField.d.ts +1 -1
- package/dist/widgets/ObjectRefField.d.ts +1 -1
- package/dist/widgets/OptionsEmptyState.d.ts +59 -0
- package/dist/widgets/PercentField.d.ts +1 -1
- package/dist/widgets/PhoneField.d.ts +1 -1
- package/dist/widgets/QRCodeField.d.ts +1 -1
- package/dist/widgets/RadioField.d.ts +1 -1
- package/dist/widgets/RatingField.d.ts +1 -1
- package/dist/widgets/RecipientPickerField.d.ts +1 -1
- package/dist/widgets/RecordPickerDialog.d.ts +49 -7
- package/dist/widgets/RichTextField.d.ts +19 -1
- package/dist/widgets/SelectField.d.ts +25 -5
- package/dist/widgets/TagsField.d.ts +1 -1
- package/dist/widgets/TextAreaField.d.ts +44 -5
- package/dist/widgets/UrlField.d.ts +1 -1
- package/dist/widgets/address-format.d.ts +68 -0
- package/dist/widgets/file-size-guard.d.ts +41 -0
- package/dist/widgets/nativeDateValue.d.ts +37 -0
- package/dist/widgets/toDomProps.d.ts +111 -0
- package/dist/widgets/toHostGroupProps.d.ts +91 -0
- package/dist/widgets/types.d.ts +128 -33
- package/dist/widgets/useRecordQuery.d.ts +7 -1
- package/dist/withFieldCarrier.d.ts +56 -0
- package/package.json +20 -16
- package/src/FieldEditWidget.tsx +17 -1
- package/src/__tests__/AddressCellRenderer.test.tsx +166 -0
- package/src/__tests__/CurrencyField.minorUnits.test.tsx +191 -0
- package/src/__tests__/CurrencyField.symbol.test.tsx +198 -0
- package/src/__tests__/DateCellRenderer.test.tsx +9 -0
- package/src/__tests__/NumberCellRenderer.grouping.test.tsx +146 -0
- package/src/__tests__/PercentCellRenderer.locale.test.tsx +152 -0
- package/src/__tests__/PercentCellRenderer.test.tsx +115 -0
- package/src/__tests__/boolean-label-association-e2e.test.tsx +298 -0
- package/src/__tests__/capability-multiselect-retired.test.ts +109 -0
- package/src/__tests__/cell-truncation.test.tsx +96 -0
- package/src/__tests__/composite-group-label-e2e.test.tsx +436 -0
- package/src/__tests__/composite-group-label-readonly-e2e.test.tsx +403 -0
- package/src/__tests__/date-formatter-residue-4272.test.ts +120 -0
- package/src/__tests__/date-locale-channel.test.tsx +305 -0
- package/src/__tests__/field-carrier-sdui.test.tsx +169 -0
- package/src/__tests__/formatCurrency.centsDigit.test.tsx +158 -0
- package/src/__tests__/formatCurrency.minorUnits.test.tsx +221 -0
- package/src/__tests__/group-labelling-declaration.test.ts +148 -0
- package/src/__tests__/lookupCellRecordLink.test.tsx +171 -0
- package/src/__tests__/percent-cell-vs-measure-4576.test.ts +115 -0
- package/src/__tests__/percent-formatter-locale-4553.test.ts +147 -0
- package/src/__tests__/percent-tie-halfup-4590.test.ts +224 -0
- package/src/__tests__/select-label-association-e2e.test.tsx +199 -0
- package/src/__tests__/spec-symbol-batch7.test.ts +29 -15
- package/src/__tests__/validation-feedback.test.tsx +22 -13
- package/src/__tests__/widget-aria-invalid-e2e.test.tsx +265 -0
- package/src/__tests__/widget-aria-invalid-registry-e2e.test.tsx +338 -0
- package/src/__tests__/widget-dom-leak-e2e.test.tsx +357 -0
- package/src/__tests__/widget-props-contract.test.tsx +22 -9
- package/src/complex-widgets.test.tsx +22 -6
- package/src/currency.ts +130 -0
- package/src/datetime-widgets.test.tsx +94 -2
- package/src/field-type-alias.multiple.test.ts +81 -0
- package/src/field-type-alias.ts +58 -2
- package/src/index.css +44 -0
- package/src/index.tsx +558 -268
- package/src/standard-widgets.test.tsx +8 -1
- package/src/widgets/AddressField.postalCode.test.tsx +257 -0
- package/src/widgets/AddressField.tsx +107 -38
- package/src/widgets/AddressField.uniqueIds.test.tsx +93 -0
- package/src/widgets/AvatarField.tsx +9 -2
- package/src/widgets/BooleanField.tsx +44 -10
- package/src/widgets/CapabilityMultiSelectField.tsx +17 -5
- package/src/widgets/CharacterCount.tsx +263 -0
- package/src/widgets/CheckboxesField.tsx +66 -16
- package/src/widgets/CodeField.tsx +9 -2
- package/src/widgets/ColorField.tsx +11 -2
- package/src/widgets/CurrencyField.tsx +60 -19
- package/src/widgets/DateField.tsx +13 -4
- package/src/widgets/DateTimeField.tsx +14 -5
- package/src/widgets/EmailField.tsx +5 -5
- package/src/widgets/FileField.tsx +39 -11
- package/src/widgets/FilterConditionField.tsx +11 -0
- package/src/widgets/FormulaField.tsx +7 -2
- package/src/widgets/FullscreenFieldEditor.tsx +60 -0
- package/src/widgets/GeolocationField.tsx +49 -8
- package/src/widgets/GeolocationField.uniqueIds.test.tsx +88 -0
- package/src/widgets/GridField.test.tsx +226 -0
- package/src/widgets/GridField.tsx +115 -11
- package/src/widgets/ImageField.maxSize.test.tsx +154 -0
- package/src/widgets/ImageField.tsx +63 -6
- package/src/widgets/LocationField.tsx +9 -2
- package/src/widgets/LookupField.gateHintLabel.test.tsx +135 -0
- package/src/widgets/LookupField.hydration.test.tsx +1 -1
- package/src/widgets/LookupField.tsx +49 -10
- package/src/widgets/MasterDetailField.tsx +1 -1
- package/src/widgets/MultiSelectField.tsx +86 -16
- package/src/widgets/NumberField.tsx +3 -3
- package/src/widgets/ObjectField.tsx +17 -8
- package/src/widgets/ObjectRefField.tsx +10 -0
- package/src/widgets/OptionsEmptyState.no-provider.test.tsx +88 -0
- package/src/widgets/OptionsEmptyState.test.tsx +169 -0
- package/src/widgets/OptionsEmptyState.tsx +99 -0
- package/src/widgets/PasswordField.tsx +3 -3
- package/src/widgets/PeoplePicker.tsx +7 -1
- package/src/widgets/PercentField.tsx +5 -4
- package/src/widgets/PhoneField.tsx +5 -5
- package/src/widgets/QRCodeField.tsx +9 -2
- package/src/widgets/RadioField.tsx +58 -16
- package/src/widgets/RatingField.tsx +32 -4
- package/src/widgets/RecipientPickerField.tsx +18 -0
- package/src/widgets/RecordPickerDialog.baseFilterShapes.test.tsx +191 -0
- package/src/widgets/RecordPickerDialog.dateLocale.test.tsx +124 -0
- package/src/widgets/RecordPickerDialog.filterOptions.test.tsx +611 -0
- package/src/widgets/RecordPickerDialog.selectLabel.test.tsx +112 -0
- package/src/widgets/RecordPickerDialog.tsx +235 -21
- package/src/widgets/RichTextField.tsx +151 -24
- package/src/widgets/SelectField.tsx +84 -22
- package/src/widgets/SliderField.tsx +1 -1
- package/src/widgets/SummaryField.tsx +1 -1
- package/src/widgets/TagsField.placeholder.no-provider.test.tsx +68 -0
- package/src/widgets/TagsField.placeholder.test.tsx +95 -0
- package/src/widgets/TagsField.tsx +23 -2
- package/src/widgets/TextAreaField.tsx +171 -93
- package/src/widgets/TextField.tsx +3 -3
- package/src/widgets/TimeField.tsx +2 -2
- package/src/widgets/UrlField.tsx +5 -5
- package/src/widgets/UserField.tsx +4 -3
- package/src/widgets/VectorField.tsx +1 -1
- package/src/widgets/__tests__/FilterConditionField.operators.test.ts +25 -1
- package/src/widgets/__tests__/FullscreenFieldEditor.i18n.test.tsx +248 -0
- package/src/widgets/__tests__/FullscreenFieldEditor.no-provider.test.tsx +116 -0
- package/src/widgets/__tests__/RichTextField.fullscreenDisabled.test.tsx +244 -0
- package/src/widgets/__tests__/RichTextField.mobileFullscreen.test.tsx +195 -0
- package/src/widgets/__tests__/TextAreaField.characterCount.announcements.test.tsx +417 -0
- package/src/widgets/__tests__/TextAreaField.characterCount.i18n.test.tsx +287 -0
- package/src/widgets/__tests__/TextAreaField.characterCount.no-provider.test.tsx +160 -0
- package/src/widgets/__tests__/TextAreaField.fullscreenCharacterCount.i18n.test.tsx +161 -0
- package/src/widgets/__tests__/TextAreaField.fullscreenCharacterCount.test.tsx +346 -0
- package/src/widgets/__tests__/TextAreaField.fullscreenDisabled.test.tsx +246 -0
- package/src/widgets/__tests__/TextAreaField.mobileFullscreen.test.tsx +175 -0
- package/src/widgets/address-format.ts +120 -0
- package/src/widgets/file-size-guard.ts +55 -0
- package/src/widgets/nativeDateValue.test.ts +115 -0
- package/src/widgets/nativeDateValue.ts +112 -0
- package/src/widgets/optionWidgets.gatedOptions.test.tsx +267 -0
- package/src/widgets/optionWidgets.unconfiguredOptions.test.tsx +150 -0
- package/src/widgets/toDomProps.ts +204 -0
- package/src/widgets/toHostGroupProps.ts +102 -0
- package/src/widgets/types.ts +135 -35
- package/src/widgets/useFieldTranslation.ts +46 -4
- package/src/widgets/useRecordQuery.ts +30 -3
- package/src/withFieldCarrier.tsx +75 -0
- package/dist/FieldEditWidget.test.d.ts +0 -8
- package/dist/__tests__/DateCellRenderer.test.d.ts +0 -0
- package/dist/__tests__/NumberCellRenderer.test.d.ts +0 -0
- package/dist/__tests__/lookupCellDisplayField.test.d.ts +0 -0
- package/dist/__tests__/lookupCellDisplayName.test.d.ts +0 -0
- package/dist/__tests__/lookupCellReferenceKey.test.d.ts +0 -0
- package/dist/__tests__/registry-collision.test.d.ts +0 -0
- package/dist/__tests__/resolveFieldCurrency.test.d.ts +0 -1
- package/dist/__tests__/spec-symbol-batch7.test.d.ts +0 -8
- package/dist/__tests__/validation-feedback.test.d.ts +0 -0
- package/dist/__tests__/widget-props-contract.test.d.ts +0 -8
- package/dist/coerce-safe-value.test.d.ts +0 -1
- package/dist/complex-widgets.test.d.ts +0 -1
- package/dist/datetime-widgets.test.d.ts +0 -1
- package/dist/field-type-coverage.test.d.ts +0 -1
- package/dist/standard-widgets.test.d.ts +0 -0
- package/dist/widgets/CapabilityMultiSelectField.test.d.ts +0 -0
- package/dist/widgets/CheckboxesField.cascade.test.d.ts +0 -0
- package/dist/widgets/GridField.test.d.ts +0 -1
- package/dist/widgets/ImageLightbox.test.d.ts +0 -1
- package/dist/widgets/LookupField.dependsOn.test.d.ts +0 -8
- package/dist/widgets/LookupField.hydration.test.d.ts +0 -1
- package/dist/widgets/LookupField.idField.test.d.ts +0 -1
- package/dist/widgets/MultiSelectField.cascade.test.d.ts +0 -0
- package/dist/widgets/PeoplePicker.test.d.ts +0 -8
- package/dist/widgets/PeoplePickerComponents.test.d.ts +0 -8
- package/dist/widgets/RadioField.cascade.test.d.ts +0 -0
- package/dist/widgets/RecipientPickerField.test.d.ts +0 -0
- package/dist/widgets/SelectField.cascade.test.d.ts +0 -0
- package/dist/widgets/UserFieldPicker.test.d.ts +0 -8
- package/dist/widgets/__tests__/FilterConditionField.matchAll.test.d.ts +0 -8
- package/dist/widgets/__tests__/FilterConditionField.operators.test.d.ts +0 -8
- package/dist/widgets/deriveLookupColumns.test.d.ts +0 -1
- package/dist/widgets/file-value.test.d.ts +0 -1
- package/dist/widgets/personDisplay.test.d.ts +0 -8
- package/dist/widgets/recentLookups.test.d.ts +0 -1
- package/dist/widgets/useRecordQuery.test.d.ts +0 -8
- package/dist/widgets/useUploadingSignal.test.d.ts +0 -1
|
@@ -10,7 +10,16 @@
|
|
|
10
10
|
* P3.2 Field Widget Polish - Validation Feedback
|
|
11
11
|
*
|
|
12
12
|
* Tests that field widgets consistently handle validation feedback:
|
|
13
|
-
*
|
|
13
|
+
* `error` prop, aria-invalid attribute, and disabled states.
|
|
14
|
+
*
|
|
15
|
+
* The slot is `error` — the name `@objectstack/spec/ui`'s
|
|
16
|
+
* `FieldWidgetPropsSchema` gives it — since objectui#3222. These are the
|
|
17
|
+
* CONSUMER half only: they prove a widget handed a message marks its control
|
|
18
|
+
* invalid. That was true before #3222 too, under the name `errorMessage`, and
|
|
19
|
+
* it did not help anyone, because no host ever passed the prop. The PRODUCER
|
|
20
|
+
* half is `form-error-delivery.test.tsx` in `@object-ui/components` plus
|
|
21
|
+
* `widget-aria-invalid-e2e.test.tsx` next to this file; a rename alone would
|
|
22
|
+
* have swapped one dead key for another.
|
|
14
23
|
*/
|
|
15
24
|
|
|
16
25
|
import { describe, it, expect, vi } from 'vitest';
|
|
@@ -32,23 +41,23 @@ const noop = vi.fn();
|
|
|
32
41
|
|
|
33
42
|
describe('P3.2 Validation Feedback', () => {
|
|
34
43
|
// ---------------------------------------------------------------
|
|
35
|
-
// aria-invalid on
|
|
44
|
+
// aria-invalid on `error`
|
|
36
45
|
// ---------------------------------------------------------------
|
|
37
46
|
describe('aria-invalid attribute', () => {
|
|
38
|
-
it('EmailField sets aria-invalid when
|
|
47
|
+
it('EmailField sets aria-invalid when `error` provided', () => {
|
|
39
48
|
render(
|
|
40
49
|
<EmailField
|
|
41
50
|
value=""
|
|
42
51
|
onChange={noop}
|
|
43
52
|
field={{ type: 'email' } as any}
|
|
44
|
-
|
|
53
|
+
error="Invalid email"
|
|
45
54
|
/>
|
|
46
55
|
);
|
|
47
56
|
const input = screen.getByRole('textbox');
|
|
48
57
|
expect(input).toHaveAttribute('aria-invalid', 'true');
|
|
49
58
|
});
|
|
50
59
|
|
|
51
|
-
it('EmailField does not set aria-invalid without
|
|
60
|
+
it('EmailField does not set aria-invalid without `error`', () => {
|
|
52
61
|
render(
|
|
53
62
|
<EmailField
|
|
54
63
|
value=""
|
|
@@ -60,52 +69,52 @@ describe('P3.2 Validation Feedback', () => {
|
|
|
60
69
|
expect(input).not.toHaveAttribute('aria-invalid', 'true');
|
|
61
70
|
});
|
|
62
71
|
|
|
63
|
-
it('UrlField sets aria-invalid when
|
|
72
|
+
it('UrlField sets aria-invalid when `error` provided', () => {
|
|
64
73
|
render(
|
|
65
74
|
<UrlField
|
|
66
75
|
value=""
|
|
67
76
|
onChange={noop}
|
|
68
77
|
field={{ type: 'url' } as any}
|
|
69
|
-
|
|
78
|
+
error="Invalid URL"
|
|
70
79
|
/>
|
|
71
80
|
);
|
|
72
81
|
const input = screen.getByDisplayValue('');
|
|
73
82
|
expect(input).toHaveAttribute('aria-invalid', 'true');
|
|
74
83
|
});
|
|
75
84
|
|
|
76
|
-
it('PhoneField sets aria-invalid when
|
|
85
|
+
it('PhoneField sets aria-invalid when `error` provided', () => {
|
|
77
86
|
render(
|
|
78
87
|
<PhoneField
|
|
79
88
|
value=""
|
|
80
89
|
onChange={noop}
|
|
81
90
|
field={{ type: 'phone' } as any}
|
|
82
|
-
|
|
91
|
+
error="Invalid phone"
|
|
83
92
|
/>
|
|
84
93
|
);
|
|
85
94
|
const input = screen.getByRole('textbox');
|
|
86
95
|
expect(input).toHaveAttribute('aria-invalid', 'true');
|
|
87
96
|
});
|
|
88
97
|
|
|
89
|
-
it('TextAreaField sets aria-invalid when
|
|
98
|
+
it('TextAreaField sets aria-invalid when `error` provided', () => {
|
|
90
99
|
render(
|
|
91
100
|
<TextAreaField
|
|
92
101
|
value=""
|
|
93
102
|
onChange={noop}
|
|
94
103
|
field={{ type: 'textarea' } as any}
|
|
95
|
-
|
|
104
|
+
error="Required"
|
|
96
105
|
/>
|
|
97
106
|
);
|
|
98
107
|
const textarea = screen.getByRole('textbox');
|
|
99
108
|
expect(textarea).toHaveAttribute('aria-invalid', 'true');
|
|
100
109
|
});
|
|
101
110
|
|
|
102
|
-
it('CurrencyField sets aria-invalid when
|
|
111
|
+
it('CurrencyField sets aria-invalid when `error` provided', () => {
|
|
103
112
|
render(
|
|
104
113
|
<CurrencyField
|
|
105
114
|
value={0}
|
|
106
115
|
onChange={noop}
|
|
107
116
|
field={{ type: 'currency' } as any}
|
|
108
|
-
|
|
117
|
+
error="Must be positive"
|
|
109
118
|
/>
|
|
110
119
|
);
|
|
111
120
|
const input = screen.getByRole('spinbutton');
|
|
@@ -0,0 +1,265 @@
|
|
|
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
|
+
/**
|
|
10
|
+
* End-to-end: a REAL widget, inside the REAL form renderer, announces an
|
|
11
|
+
* invalid field to assistive tech (objectui#3222).
|
|
12
|
+
*
|
|
13
|
+
* The two halves of this contract have unit tests of their own — the widgets
|
|
14
|
+
* mark themselves invalid when handed an `error`
|
|
15
|
+
* (`validation-feedback.test.tsx`), and the form renderer produces one
|
|
16
|
+
* (`form-error-delivery.test.tsx` in `@object-ui/components`). Neither alone
|
|
17
|
+
* would have caught the actual defect, because the defect was precisely that
|
|
18
|
+
* the two halves never met: the widgets read `errorMessage`, the spec's
|
|
19
|
+
* published contract said `error`, and NOTHING in `packages/` or `apps/`
|
|
20
|
+
* produced either. Seven widgets computed `aria-invalid={!!errorMessage}` from
|
|
21
|
+
* a value that was `undefined` forever, so `aria-invalid` had never once been
|
|
22
|
+
* set on a failing field.
|
|
23
|
+
*
|
|
24
|
+
* So this file joins them: real react-hook-form validation, real widget, one
|
|
25
|
+
* assertion per widget that the control is `aria-invalid="true"` after the
|
|
26
|
+
* failure and `"false"` before it. `aria-invalid="false"` up front is the load
|
|
27
|
+
* bearing half of each pair — `<FormControl>` is a Radix `Slot` that hands its
|
|
28
|
+
* child a correct `aria-invalid`, and the widget's own attribute is written
|
|
29
|
+
* AFTER the props spread, so it wins. A widget computing it from a prop nobody
|
|
30
|
+
* passes does not merely miss the signal, it OVERWRITES the correct one with
|
|
31
|
+
* `false`.
|
|
32
|
+
*
|
|
33
|
+
* The widgets are registered raw rather than through `registerAllFields()`,
|
|
34
|
+
* which wraps every loader in `React.lazy`: an unbounded module load inside a
|
|
35
|
+
* bounded `findBy`/`waitFor` window is the repo's known flake generator
|
|
36
|
+
* (AGENTS.md 测试纪律, objectui#3010). Same component, no Suspense boundary.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
import { describe, it, expect, beforeAll, beforeEach, afterEach, vi } from 'vitest';
|
|
40
|
+
import { render, screen, fireEvent, waitFor, cleanup } from '@testing-library/react';
|
|
41
|
+
import '@testing-library/jest-dom';
|
|
42
|
+
import { ComponentRegistry } from '@object-ui/core';
|
|
43
|
+
// Module scope: pulls in the form renderer's registration side effect.
|
|
44
|
+
import '@object-ui/components';
|
|
45
|
+
|
|
46
|
+
import { EmailField } from '../widgets/EmailField';
|
|
47
|
+
import { PhoneField } from '../widgets/PhoneField';
|
|
48
|
+
import { UrlField } from '../widgets/UrlField';
|
|
49
|
+
import { TextAreaField } from '../widgets/TextAreaField';
|
|
50
|
+
import { CurrencyField } from '../widgets/CurrencyField';
|
|
51
|
+
import { PercentField } from '../widgets/PercentField';
|
|
52
|
+
import { RichTextField } from '../widgets/RichTextField';
|
|
53
|
+
import { TextField } from '../widgets/TextField';
|
|
54
|
+
import { SelectField } from '../widgets/SelectField';
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The widgets that read the validation slot, by their form-path key: the seven
|
|
58
|
+
* from objectui#3222, plus `select` (objectui#3306) — the widget whose control
|
|
59
|
+
* is a Radix trigger rather than a native input, where every aria-* used to be
|
|
60
|
+
* swallowed by the non-DOM `Select.Root`.
|
|
61
|
+
*/
|
|
62
|
+
const WIDGETS = [
|
|
63
|
+
['email', EmailField],
|
|
64
|
+
['phone', PhoneField],
|
|
65
|
+
['url', UrlField],
|
|
66
|
+
['textarea', TextAreaField],
|
|
67
|
+
['currency', CurrencyField],
|
|
68
|
+
['percent', PercentField],
|
|
69
|
+
['markdown', RichTextField],
|
|
70
|
+
['select', SelectField],
|
|
71
|
+
] as const;
|
|
72
|
+
|
|
73
|
+
beforeAll(() => {
|
|
74
|
+
for (const [type, Widget] of WIDGETS) {
|
|
75
|
+
ComponentRegistry.register(type, Widget as any, { namespace: 'field', skipFallback: true });
|
|
76
|
+
}
|
|
77
|
+
}, 30000);
|
|
78
|
+
|
|
79
|
+
beforeEach(() => {
|
|
80
|
+
if (!(Element.prototype as any).scrollIntoView) {
|
|
81
|
+
(Element.prototype as any).scrollIntoView = () => {};
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
afterEach(() => {
|
|
86
|
+
cleanup();
|
|
87
|
+
vi.restoreAllMocks();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
function renderForm(field: any, defaultValue: unknown) {
|
|
91
|
+
const Form = ComponentRegistry.get('form')!;
|
|
92
|
+
return render(
|
|
93
|
+
<Form
|
|
94
|
+
schema={{
|
|
95
|
+
type: 'form',
|
|
96
|
+
mode: 'create',
|
|
97
|
+
showSubmit: true,
|
|
98
|
+
showCancel: false,
|
|
99
|
+
submitLabel: 'Create',
|
|
100
|
+
defaultValues: { [field.name]: defaultValue },
|
|
101
|
+
fields: [field],
|
|
102
|
+
onSubmit: () => {},
|
|
103
|
+
}}
|
|
104
|
+
/>,
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The control the widget rendered, located through the form row rather than by
|
|
110
|
+
* role — the seven widgets render `input[type=email|tel|url|number]` and
|
|
111
|
+
* `textarea` between them, and the point of the assertion is the ATTRIBUTE,
|
|
112
|
+
* not which element type carries it.
|
|
113
|
+
*/
|
|
114
|
+
function controlOf(name: string): Element {
|
|
115
|
+
const control = document.querySelector(
|
|
116
|
+
`[data-field="${name}"] input, [data-field="${name}"] textarea`,
|
|
117
|
+
);
|
|
118
|
+
if (!control) throw new Error(`no control rendered for field "${name}"`);
|
|
119
|
+
return control;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const submit = () => fireEvent.click(screen.getByRole('button', { name: /create/i }));
|
|
123
|
+
|
|
124
|
+
describe('field widgets announce an invalid field to AT (objectui#3222)', () => {
|
|
125
|
+
// `field:textarea` because the bare `textarea` key is a BUILTIN_FIELD_TYPE in
|
|
126
|
+
// the form renderer and never reaches the registry — it is the prefixed id
|
|
127
|
+
// (`mapFieldTypeToFormType`) that resolves to this package's widget.
|
|
128
|
+
it.each([
|
|
129
|
+
['email', 'email', ''],
|
|
130
|
+
['phone', 'phone', ''],
|
|
131
|
+
['url', 'url', ''],
|
|
132
|
+
['field:textarea', 'notes', ''],
|
|
133
|
+
['currency', 'amount', null],
|
|
134
|
+
['percent', 'ratio', null],
|
|
135
|
+
['markdown', 'body', ''],
|
|
136
|
+
] as const)(
|
|
137
|
+
'a required %s field is aria-invalid only AFTER validation fails',
|
|
138
|
+
async (type, name, emptyValue) => {
|
|
139
|
+
renderForm({ name, label: name, type, required: true }, emptyValue);
|
|
140
|
+
|
|
141
|
+
// Before the submit there is no error, and the widget must say so —
|
|
142
|
+
// this is the half that a Slot-provided `aria-invalid` cannot fake.
|
|
143
|
+
expect(controlOf(name)).toHaveAttribute('aria-invalid', 'false');
|
|
144
|
+
|
|
145
|
+
submit();
|
|
146
|
+
|
|
147
|
+
await waitFor(() => {
|
|
148
|
+
expect(controlOf(name)).toHaveAttribute('aria-invalid', 'true');
|
|
149
|
+
});
|
|
150
|
+
},
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
it('the message itself is rendered once, by the form — not by the widget', async () => {
|
|
154
|
+
// Responsibility split (the ruling's scope item 3): the widget consumes
|
|
155
|
+
// `error` for `aria-invalid` ONLY. `<FormMessage/>` owns the text; a widget
|
|
156
|
+
// that printed it too would show the user the same sentence twice.
|
|
157
|
+
renderForm({ name: 'email', label: 'Email', type: 'email', required: true }, '');
|
|
158
|
+
|
|
159
|
+
submit();
|
|
160
|
+
|
|
161
|
+
await waitFor(() => expect(screen.getAllByText('Email is required')).toHaveLength(1));
|
|
162
|
+
// And the message is NOT inside the control the widget rendered.
|
|
163
|
+
expect(controlOf('email')).not.toHaveTextContent('Email is required');
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('a widget that does NOT read `error` is still marked invalid, by the Slot', async () => {
|
|
167
|
+
// The counterpart that makes the diagnosis precise: `TextField` never
|
|
168
|
+
// computed its own `aria-invalid`, so `<FormControl>`'s Slot value reached
|
|
169
|
+
// its input untouched and it announced invalid fields correctly all along.
|
|
170
|
+
// Only the seven widgets that DID compute one were broken — they wrote
|
|
171
|
+
// theirs after the props spread, so `!!undefined` won.
|
|
172
|
+
//
|
|
173
|
+
// Pinned because the obvious "cleanup" here is to stop forwarding `error`
|
|
174
|
+
// to widgets that do not declare a use for it. That cannot be known (a
|
|
175
|
+
// third-party widget is exactly the case the contract exists for), and
|
|
176
|
+
// withholding it would recreate declared-≠-delivered one widget at a time.
|
|
177
|
+
ComponentRegistry.register('plaintext', TextField as any, { namespace: 'field', skipFallback: true });
|
|
178
|
+
renderForm({ name: 'title', label: 'Title', type: 'plaintext', required: true }, '');
|
|
179
|
+
|
|
180
|
+
submit();
|
|
181
|
+
|
|
182
|
+
await waitFor(() => expect(controlOf('title')).toHaveAttribute('aria-invalid', 'true'));
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('clears the invalid state when the field becomes valid again', async () => {
|
|
186
|
+
renderForm({ name: 'email', label: 'Email', type: 'email', required: true }, '');
|
|
187
|
+
|
|
188
|
+
submit();
|
|
189
|
+
await waitFor(() => expect(controlOf('email')).toHaveAttribute('aria-invalid', 'true'));
|
|
190
|
+
|
|
191
|
+
fireEvent.change(controlOf('email'), { target: { value: 'a@example.com' } });
|
|
192
|
+
|
|
193
|
+
await waitFor(() => expect(controlOf('email')).toHaveAttribute('aria-invalid', 'false'));
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
describe('field:select announces validation state on its TRIGGER (objectui#3306)', () => {
|
|
198
|
+
// Radix `Select.Root` renders no DOM element and silently drops every prop
|
|
199
|
+
// it does not recognise. The widget used to spread its DOM pass-through onto
|
|
200
|
+
// Root, so `aria-invalid` / `aria-describedby` / `aria-required` all
|
|
201
|
+
// vanished: a failed required select showed the red message while assistive
|
|
202
|
+
// tech was told nothing. The real control is the focusable
|
|
203
|
+
// `<button role="combobox">` the trigger renders — that is where every
|
|
204
|
+
// assertion below reads from, never a wrapper.
|
|
205
|
+
//
|
|
206
|
+
// `field:select` (not bare `select`) because `select` is a
|
|
207
|
+
// BUILTIN_FIELD_TYPE in the form renderer and never reaches the registry —
|
|
208
|
+
// same reason as `field:textarea` above.
|
|
209
|
+
const OPTIONS = [
|
|
210
|
+
{ label: 'Alpha', value: 'alpha' },
|
|
211
|
+
{ label: 'Beta', value: 'beta' },
|
|
212
|
+
];
|
|
213
|
+
|
|
214
|
+
const selectField = {
|
|
215
|
+
name: 'choice',
|
|
216
|
+
label: 'Choice',
|
|
217
|
+
type: 'field:select',
|
|
218
|
+
required: true,
|
|
219
|
+
options: OPTIONS,
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
/** The trigger button, by role — fails loudly if it stops being a combobox. */
|
|
223
|
+
function trigger(): Element {
|
|
224
|
+
const el = document.querySelector('[data-field="choice"] [role="combobox"]');
|
|
225
|
+
if (!el) throw new Error('no select trigger rendered for field "choice"');
|
|
226
|
+
return el;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
it('a required select is aria-invalid only AFTER validation fails, on the trigger', async () => {
|
|
230
|
+
renderForm(selectField, null);
|
|
231
|
+
|
|
232
|
+
// The explicit "false" half is load-bearing, same as the widgets above: a
|
|
233
|
+
// valid field SAYS it is valid rather than staying mute.
|
|
234
|
+
expect(trigger()).toHaveAttribute('aria-invalid', 'false');
|
|
235
|
+
|
|
236
|
+
submit();
|
|
237
|
+
|
|
238
|
+
// Prove the failure actually rendered before reading aria off it — an
|
|
239
|
+
// error variant that silently produces no error tests nothing.
|
|
240
|
+
await waitFor(() =>
|
|
241
|
+
expect(screen.getAllByText('Choice is required')).toHaveLength(1),
|
|
242
|
+
);
|
|
243
|
+
expect(trigger()).toHaveAttribute('aria-invalid', 'true');
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it('carries aria-required on the trigger — the state channel of objectui#3290', () => {
|
|
247
|
+
renderForm(selectField, null);
|
|
248
|
+
|
|
249
|
+
// Root would swallow it; the trigger is "the control" for a Radix select.
|
|
250
|
+
expect(trigger()).toHaveAttribute('aria-required', 'true');
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it('aria-describedby on the trigger references the rendered error message', async () => {
|
|
254
|
+
renderForm(selectField, null);
|
|
255
|
+
|
|
256
|
+
submit();
|
|
257
|
+
|
|
258
|
+
const message = await screen.findByText('Choice is required');
|
|
259
|
+
// The association is only real if the id chain closes: the trigger must
|
|
260
|
+
// point at the exact element carrying the message text.
|
|
261
|
+
expect(message.id).not.toBe('');
|
|
262
|
+
const describedBy = trigger().getAttribute('aria-describedby') ?? '';
|
|
263
|
+
expect(describedBy.split(/\s+/)).toContain(message.id);
|
|
264
|
+
});
|
|
265
|
+
});
|