@open-mercato/ui 0.10.1-develop.8129.1.149839452c → 0.10.1-develop.8143.1.bf633ea932
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/dist/backend/CrudForm.js +65 -35
- package/dist/backend/CrudForm.js.map +2 -2
- package/dist/backend/detail/NotesSection.js +3 -2
- package/dist/backend/detail/NotesSection.js.map +2 -2
- package/dist/backend/inputs/ComboboxInput.js +1 -1
- package/dist/backend/inputs/ComboboxInput.js.map +2 -2
- package/dist/backend/inputs/LookupSelect.js +117 -35
- package/dist/backend/inputs/LookupSelect.js.map +2 -2
- package/package.json +3 -3
- package/src/backend/CrudForm.tsx +168 -100
- package/src/backend/__tests__/CrudForm.accessibleLabels.test.tsx +108 -0
- package/src/backend/__tests__/CrudForm.doubleSubmit.test.tsx +85 -1
- package/src/backend/__tests__/CrudForm.injectionLifecycle.test.tsx +5 -2
- package/src/backend/__tests__/NotesSection.test.tsx +48 -1
- package/src/backend/detail/NotesSection.tsx +3 -2
- package/src/backend/inputs/ComboboxInput.tsx +2 -2
- package/src/backend/inputs/LookupSelect.tsx +166 -53
- package/src/backend/inputs/__tests__/ComboboxInput.test.tsx +22 -0
- package/src/backend/inputs/__tests__/LookupSelect.test.tsx +209 -23
package/src/backend/CrudForm.tsx
CHANGED
|
@@ -1396,13 +1396,15 @@ function CrudFormImpl<TValues extends Record<string, unknown>>({
|
|
|
1396
1396
|
)
|
|
1397
1397
|
|
|
1398
1398
|
const navigateWithGuard = React.useCallback(
|
|
1399
|
-
async (target: string) => {
|
|
1400
|
-
if (!target) return
|
|
1399
|
+
async (target: string): Promise<boolean> => {
|
|
1400
|
+
if (!target) return false
|
|
1401
1401
|
const allowed = await canNavigateTo(target)
|
|
1402
1402
|
if (allowed) {
|
|
1403
1403
|
allowNextNavigation()
|
|
1404
1404
|
router.push(target)
|
|
1405
|
+
return true
|
|
1405
1406
|
}
|
|
1407
|
+
return false
|
|
1406
1408
|
},
|
|
1407
1409
|
[allowNextNavigation, canNavigateTo, router],
|
|
1408
1410
|
)
|
|
@@ -3119,6 +3121,7 @@ function CrudFormImpl<TValues extends Record<string, unknown>>({
|
|
|
3119
3121
|
if (formReadOnly) return
|
|
3120
3122
|
if (submittingRef.current) return
|
|
3121
3123
|
submittingRef.current = true
|
|
3124
|
+
let redirectNavigationStarted = false
|
|
3122
3125
|
try {
|
|
3123
3126
|
setFormError(null)
|
|
3124
3127
|
setErrors({})
|
|
@@ -3376,7 +3379,7 @@ function CrudFormImpl<TValues extends Record<string, unknown>>({
|
|
|
3376
3379
|
logger.error('Error in onSubmitSuccess', { err })
|
|
3377
3380
|
getTelemetryRuntime()?.reportError(err, { module: 'ui', code: 'ui.form_submit_success_failed' })
|
|
3378
3381
|
}
|
|
3379
|
-
if (successRedirect) await navigateWithGuard(successRedirect)
|
|
3382
|
+
if (successRedirect) redirectNavigationStarted = await navigateWithGuard(successRedirect)
|
|
3380
3383
|
} catch (err: unknown) {
|
|
3381
3384
|
clearSubmitNavigationBypass()
|
|
3382
3385
|
try {
|
|
@@ -3448,10 +3451,14 @@ function CrudFormImpl<TValues extends Record<string, unknown>>({
|
|
|
3448
3451
|
}
|
|
3449
3452
|
setFormError(displayMessage)
|
|
3450
3453
|
} finally {
|
|
3451
|
-
|
|
3454
|
+
// A successful submit that kicks off the success-redirect keeps the form
|
|
3455
|
+
// "pending"/locked until it actually unmounts, so a second submit fired
|
|
3456
|
+
// during router navigation (which resolves well before unmount) doesn't
|
|
3457
|
+
// re-run onSubmit and create a duplicate record.
|
|
3458
|
+
if (!redirectNavigationStarted) setPending(false)
|
|
3452
3459
|
}
|
|
3453
3460
|
} finally {
|
|
3454
|
-
submittingRef.current = false
|
|
3461
|
+
if (!redirectNavigationStarted) submittingRef.current = false
|
|
3455
3462
|
}
|
|
3456
3463
|
}
|
|
3457
3464
|
|
|
@@ -3607,6 +3614,7 @@ function CrudFormImpl<TValues extends Record<string, unknown>>({
|
|
|
3607
3614
|
entityIdForField={primaryEntityId ?? undefined}
|
|
3608
3615
|
recordId={explicitResourceId ?? recordId}
|
|
3609
3616
|
markRequired={widgetRequiredFieldIds.has(f.id)}
|
|
3617
|
+
formId={formId}
|
|
3610
3618
|
/>
|
|
3611
3619
|
)
|
|
3612
3620
|
})}
|
|
@@ -4182,6 +4190,7 @@ function CrudFormImpl<TValues extends Record<string, unknown>>({
|
|
|
4182
4190
|
entityIdForField={primaryEntityId ?? undefined}
|
|
4183
4191
|
recordId={explicitResourceId ?? recordId}
|
|
4184
4192
|
markRequired={widgetRequiredFieldIds.has(f.id)}
|
|
4193
|
+
formId={formId}
|
|
4185
4194
|
/>
|
|
4186
4195
|
)
|
|
4187
4196
|
})}
|
|
@@ -4273,6 +4282,7 @@ function RelationSelect({
|
|
|
4273
4282
|
}
|
|
4274
4283
|
// Local-buffer text input to avoid focus loss when parent re-renders
|
|
4275
4284
|
function TextInput({
|
|
4285
|
+
id,
|
|
4276
4286
|
value,
|
|
4277
4287
|
onChange,
|
|
4278
4288
|
placeholder,
|
|
@@ -4283,6 +4293,7 @@ function TextInput({
|
|
|
4283
4293
|
suggestions,
|
|
4284
4294
|
inputType = 'text',
|
|
4285
4295
|
}: {
|
|
4296
|
+
id?: string
|
|
4286
4297
|
value: string
|
|
4287
4298
|
onChange: (v: string) => void
|
|
4288
4299
|
placeholder?: string
|
|
@@ -4339,6 +4350,7 @@ function TextInput({
|
|
|
4339
4350
|
if (inputType === 'password') {
|
|
4340
4351
|
return (
|
|
4341
4352
|
<PasswordInput
|
|
4353
|
+
id={id}
|
|
4342
4354
|
placeholder={placeholder}
|
|
4343
4355
|
value={local}
|
|
4344
4356
|
onChange={handleChange}
|
|
@@ -4356,6 +4368,7 @@ function TextInput({
|
|
|
4356
4368
|
return (
|
|
4357
4369
|
<>
|
|
4358
4370
|
<Input
|
|
4371
|
+
id={id}
|
|
4359
4372
|
type={inputType}
|
|
4360
4373
|
placeholder={placeholder}
|
|
4361
4374
|
value={local}
|
|
@@ -4383,6 +4396,7 @@ function TextInput({
|
|
|
4383
4396
|
|
|
4384
4397
|
// Local-buffer number input to avoid focus loss when parent re-renders
|
|
4385
4398
|
function NumberInput({
|
|
4399
|
+
id,
|
|
4386
4400
|
value,
|
|
4387
4401
|
onChange,
|
|
4388
4402
|
placeholder,
|
|
@@ -4391,6 +4405,7 @@ function NumberInput({
|
|
|
4391
4405
|
disabled,
|
|
4392
4406
|
readOnly,
|
|
4393
4407
|
}: {
|
|
4408
|
+
id?: string
|
|
4394
4409
|
value: number | string | null | undefined
|
|
4395
4410
|
onChange: (v: number | undefined) => void
|
|
4396
4411
|
placeholder?: string
|
|
@@ -4471,6 +4486,7 @@ function NumberInput({
|
|
|
4471
4486
|
// against the BROWSER locale, so it discards the separator the app locale displays
|
|
4472
4487
|
// before React ever sees it (issue #5552). inputMode keeps the mobile numeric keypad.
|
|
4473
4488
|
<Input
|
|
4489
|
+
id={id}
|
|
4474
4490
|
type="text"
|
|
4475
4491
|
inputMode="decimal"
|
|
4476
4492
|
// A text input is eligible for autofill and spellcheck; a number field is not.
|
|
@@ -4492,6 +4508,7 @@ function NumberInput({
|
|
|
4492
4508
|
|
|
4493
4509
|
// Local-buffer textarea to avoid form-wide re-renders while typing
|
|
4494
4510
|
function TextAreaInput({
|
|
4511
|
+
id,
|
|
4495
4512
|
value,
|
|
4496
4513
|
onChange,
|
|
4497
4514
|
placeholder,
|
|
@@ -4502,6 +4519,7 @@ function TextAreaInput({
|
|
|
4502
4519
|
disabled,
|
|
4503
4520
|
readOnly,
|
|
4504
4521
|
}: {
|
|
4522
|
+
id?: string
|
|
4505
4523
|
value: string
|
|
4506
4524
|
onChange: (v: string) => void
|
|
4507
4525
|
placeholder?: string
|
|
@@ -4538,6 +4556,7 @@ function TextAreaInput({
|
|
|
4538
4556
|
|
|
4539
4557
|
return (
|
|
4540
4558
|
<Textarea
|
|
4559
|
+
id={id}
|
|
4541
4560
|
placeholder={placeholder}
|
|
4542
4561
|
value={local}
|
|
4543
4562
|
onChange={handleChange}
|
|
@@ -4667,6 +4686,7 @@ type FieldControlProps = {
|
|
|
4667
4686
|
entityIdForField?: string
|
|
4668
4687
|
recordId?: string
|
|
4669
4688
|
markRequired?: boolean
|
|
4689
|
+
formId: string
|
|
4670
4690
|
}
|
|
4671
4691
|
|
|
4672
4692
|
function supportsWrapperBlurValidation(field: CrudField): boolean {
|
|
@@ -4781,6 +4801,7 @@ const FieldControl = React.memo(function FieldControlImpl({
|
|
|
4781
4801
|
entityIdForField,
|
|
4782
4802
|
recordId,
|
|
4783
4803
|
markRequired,
|
|
4804
|
+
formId,
|
|
4784
4805
|
}: FieldControlProps) {
|
|
4785
4806
|
const t = useT()
|
|
4786
4807
|
const fieldSetValue = React.useCallback(
|
|
@@ -4826,6 +4847,20 @@ const FieldControl = React.memo(function FieldControlImpl({
|
|
|
4826
4847
|
? options.find((option) => option.value === singleSelectValue)?.label
|
|
4827
4848
|
: undefined
|
|
4828
4849
|
|
|
4850
|
+
// Fields rendering a single focusable control get a real htmlFor/id pair;
|
|
4851
|
+
// fields rendering a composite widget (date/time pickers, rich text, tags,
|
|
4852
|
+
// relation search, multi-value selects) fall back to aria-labelledby on a
|
|
4853
|
+
// group wrapper, per #5360's accessible-name requirement.
|
|
4854
|
+
const controlId = `${formId}-field-${field.id}`
|
|
4855
|
+
const labelId = `${controlId}-label`
|
|
4856
|
+
const hasSingleControl =
|
|
4857
|
+
field.type === 'text' ||
|
|
4858
|
+
field.type === 'password' ||
|
|
4859
|
+
field.type === 'number' ||
|
|
4860
|
+
field.type === 'textarea' ||
|
|
4861
|
+
field.type === 'combobox' ||
|
|
4862
|
+
(field.type === 'select' && !builtin?.multiple)
|
|
4863
|
+
|
|
4829
4864
|
return (
|
|
4830
4865
|
<div
|
|
4831
4866
|
className={rootClassName}
|
|
@@ -4839,13 +4874,18 @@ const FieldControl = React.memo(function FieldControlImpl({
|
|
|
4839
4874
|
: undefined}
|
|
4840
4875
|
>
|
|
4841
4876
|
{field.type !== 'checkbox' && field.label.trim().length > 0 ? (
|
|
4842
|
-
<label
|
|
4877
|
+
<label
|
|
4878
|
+
id={labelId}
|
|
4879
|
+
htmlFor={hasSingleControl ? controlId : undefined}
|
|
4880
|
+
className="block text-sm font-medium"
|
|
4881
|
+
>
|
|
4843
4882
|
{field.label}
|
|
4844
4883
|
{field.required || markRequired ? <span className="text-status-error-text"> *</span> : null}
|
|
4845
4884
|
</label>
|
|
4846
4885
|
) : null}
|
|
4847
4886
|
{field.type === 'text' && (
|
|
4848
4887
|
<TextInput
|
|
4888
|
+
id={controlId}
|
|
4849
4889
|
value={value == null ? '' : String(value)}
|
|
4850
4890
|
placeholder={placeholder}
|
|
4851
4891
|
onChange={(next) => fieldSetValue(next)}
|
|
@@ -4858,6 +4898,7 @@ const FieldControl = React.memo(function FieldControlImpl({
|
|
|
4858
4898
|
)}
|
|
4859
4899
|
{field.type === 'password' && (
|
|
4860
4900
|
<TextInput
|
|
4901
|
+
id={controlId}
|
|
4861
4902
|
value={value == null ? '' : String(value)}
|
|
4862
4903
|
placeholder={placeholder}
|
|
4863
4904
|
onChange={(next) => fieldSetValue(next)}
|
|
@@ -4870,6 +4911,7 @@ const FieldControl = React.memo(function FieldControlImpl({
|
|
|
4870
4911
|
)}
|
|
4871
4912
|
{field.type === 'number' && (
|
|
4872
4913
|
<NumberInput
|
|
4914
|
+
id={controlId}
|
|
4873
4915
|
value={typeof value === 'number' || typeof value === 'string' ? value : null}
|
|
4874
4916
|
placeholder={placeholder}
|
|
4875
4917
|
onChange={fieldSetValue}
|
|
@@ -4880,73 +4922,84 @@ const FieldControl = React.memo(function FieldControlImpl({
|
|
|
4880
4922
|
/>
|
|
4881
4923
|
)}
|
|
4882
4924
|
{field.type === 'date' && (
|
|
4883
|
-
<
|
|
4884
|
-
|
|
4885
|
-
|
|
4886
|
-
|
|
4887
|
-
|
|
4888
|
-
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4925
|
+
<div role="group" aria-labelledby={labelId}>
|
|
4926
|
+
<DatePicker
|
|
4927
|
+
value={typeof value === 'string' && value ? parseISO(value) : value instanceof Date ? value : null}
|
|
4928
|
+
onChange={(date) => setValue(field.id, date ? format(date, 'yyyy-MM-dd') : undefined)}
|
|
4929
|
+
disabled={disabled}
|
|
4930
|
+
readOnly={readOnly}
|
|
4931
|
+
placeholder={placeholder}
|
|
4932
|
+
minDate={builtin?.minDate}
|
|
4933
|
+
maxDate={builtin?.maxDate}
|
|
4934
|
+
displayFormat={builtin?.displayFormat}
|
|
4935
|
+
closeOnSelect={builtin?.closeOnSelect}
|
|
4936
|
+
locale={builtin?.locale}
|
|
4937
|
+
/>
|
|
4938
|
+
</div>
|
|
4895
4939
|
)}
|
|
4896
4940
|
{field.type === 'datetime-local' && (
|
|
4897
|
-
<
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
|
|
4908
|
-
|
|
4941
|
+
<div role="group" aria-labelledby={labelId}>
|
|
4942
|
+
<DateTimePicker
|
|
4943
|
+
value={typeof value === 'string' && value ? new Date(value) : value instanceof Date ? value : null}
|
|
4944
|
+
onChange={(date) => setValue(field.id, date ? format(date, "yyyy-MM-dd'T'HH:mm") : undefined)}
|
|
4945
|
+
disabled={disabled}
|
|
4946
|
+
readOnly={readOnly}
|
|
4947
|
+
placeholder={placeholder}
|
|
4948
|
+
minuteStep={builtin?.minuteStep}
|
|
4949
|
+
minDate={builtin?.minDate}
|
|
4950
|
+
maxDate={builtin?.maxDate}
|
|
4951
|
+
displayFormat={builtin?.displayFormat}
|
|
4952
|
+
locale={builtin?.locale}
|
|
4953
|
+
/>
|
|
4954
|
+
</div>
|
|
4909
4955
|
)}
|
|
4910
4956
|
{field.type === 'datepicker' && (
|
|
4911
|
-
<
|
|
4912
|
-
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4957
|
+
<div role="group" aria-labelledby={labelId}>
|
|
4958
|
+
<DatePicker
|
|
4959
|
+
value={typeof value === 'string' && value ? parseISO(value) : value instanceof Date ? value : null}
|
|
4960
|
+
onChange={(date) => setValue(field.id, date ? format(date, 'yyyy-MM-dd') : undefined)}
|
|
4961
|
+
disabled={disabled}
|
|
4962
|
+
readOnly={readOnly}
|
|
4963
|
+
placeholder={placeholder}
|
|
4964
|
+
minDate={builtin?.minDate}
|
|
4965
|
+
maxDate={builtin?.maxDate}
|
|
4966
|
+
displayFormat={builtin?.displayFormat}
|
|
4967
|
+
closeOnSelect={builtin?.closeOnSelect}
|
|
4968
|
+
locale={builtin?.locale}
|
|
4969
|
+
/>
|
|
4970
|
+
</div>
|
|
4923
4971
|
)}
|
|
4924
4972
|
{field.type === 'datetime' && (
|
|
4925
|
-
<
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
|
|
4936
|
-
|
|
4973
|
+
<div role="group" aria-labelledby={labelId}>
|
|
4974
|
+
<DateTimePicker
|
|
4975
|
+
value={typeof value === 'string' && value ? new Date(value) : value instanceof Date ? value : null}
|
|
4976
|
+
onChange={(date) => setValue(field.id, date ? date.toISOString() : undefined)}
|
|
4977
|
+
disabled={disabled}
|
|
4978
|
+
readOnly={readOnly}
|
|
4979
|
+
placeholder={placeholder}
|
|
4980
|
+
minuteStep={builtin?.minuteStep}
|
|
4981
|
+
minDate={builtin?.minDate}
|
|
4982
|
+
maxDate={builtin?.maxDate}
|
|
4983
|
+
displayFormat={builtin?.displayFormat}
|
|
4984
|
+
locale={builtin?.locale}
|
|
4985
|
+
/>
|
|
4986
|
+
</div>
|
|
4937
4987
|
)}
|
|
4938
4988
|
{field.type === 'time' && (
|
|
4939
|
-
<
|
|
4940
|
-
|
|
4941
|
-
|
|
4942
|
-
|
|
4943
|
-
|
|
4944
|
-
|
|
4945
|
-
|
|
4946
|
-
|
|
4989
|
+
<div role="group" aria-labelledby={labelId}>
|
|
4990
|
+
<TimePicker
|
|
4991
|
+
value={typeof value === 'string' ? value : null}
|
|
4992
|
+
onChange={(time) => setValue(field.id, time ?? undefined)}
|
|
4993
|
+
disabled={disabled}
|
|
4994
|
+
readOnly={readOnly}
|
|
4995
|
+
placeholder={placeholder}
|
|
4996
|
+
minuteStep={builtin?.minuteStep}
|
|
4997
|
+
/>
|
|
4998
|
+
</div>
|
|
4947
4999
|
)}
|
|
4948
5000
|
{field.type === 'textarea' && (
|
|
4949
5001
|
<TextAreaInput
|
|
5002
|
+
id={controlId}
|
|
4950
5003
|
value={value == null ? '' : String(value)}
|
|
4951
5004
|
placeholder={placeholder}
|
|
4952
5005
|
onChange={(next) => fieldSetValue(next)}
|
|
@@ -4959,28 +5012,37 @@ const FieldControl = React.memo(function FieldControlImpl({
|
|
|
4959
5012
|
/>
|
|
4960
5013
|
)}
|
|
4961
5014
|
{field.type === 'richtext' && builtin?.editor === 'simple' && (
|
|
4962
|
-
<
|
|
5015
|
+
<div role="group" aria-labelledby={labelId}>
|
|
5016
|
+
<SimpleMarkdownEditor value={String(value ?? '')} onChange={fieldSetValue} />
|
|
5017
|
+
</div>
|
|
4963
5018
|
)}
|
|
4964
5019
|
{field.type === 'richtext' && builtin?.editor === 'html' && (
|
|
4965
|
-
<
|
|
5020
|
+
<div role="group" aria-labelledby={labelId}>
|
|
5021
|
+
<HtmlRichEditorField value={String(value ?? '')} onChange={fieldSetValue} />
|
|
5022
|
+
</div>
|
|
4966
5023
|
)}
|
|
4967
5024
|
{field.type === 'richtext' && (!builtin?.editor || (builtin.editor !== 'simple' && builtin.editor !== 'html')) && (
|
|
4968
|
-
<
|
|
5025
|
+
<div role="group" aria-labelledby={labelId}>
|
|
5026
|
+
<MarkdownEditor value={String(value ?? '')} onChange={fieldSetValue} />
|
|
5027
|
+
</div>
|
|
4969
5028
|
)}
|
|
4970
5029
|
{field.type === 'tags' && (
|
|
4971
|
-
<
|
|
4972
|
-
|
|
4973
|
-
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
|
|
5030
|
+
<div role="group" aria-labelledby={labelId}>
|
|
5031
|
+
<TagsInput
|
|
5032
|
+
value={Array.isArray(value) ? value.filter((item): item is string => typeof item === 'string') : []}
|
|
5033
|
+
onChange={(next) => fieldSetValue(next)}
|
|
5034
|
+
placeholder={placeholder}
|
|
5035
|
+
autoFocus={autoFocusField}
|
|
5036
|
+
suppressInitialSuggestionsOnFocus={autoFocusField}
|
|
5037
|
+
suggestions={options.map((opt) => ({ value: opt.value, label: opt.label }))}
|
|
5038
|
+
loadSuggestions={loadFieldSuggestions}
|
|
5039
|
+
disabled={disabled}
|
|
5040
|
+
/>
|
|
5041
|
+
</div>
|
|
4981
5042
|
)}
|
|
4982
5043
|
{field.type === 'combobox' && (
|
|
4983
5044
|
<ComboboxInput
|
|
5045
|
+
id={controlId}
|
|
4984
5046
|
value={typeof value === 'string' ? value : String(value ?? '')}
|
|
4985
5047
|
onChange={(next) => fieldSetValue(next)}
|
|
4986
5048
|
placeholder={placeholder}
|
|
@@ -5003,8 +5065,9 @@ const FieldControl = React.memo(function FieldControlImpl({
|
|
|
5003
5065
|
/>
|
|
5004
5066
|
)}
|
|
5005
5067
|
{field.type === 'checkbox' && (
|
|
5006
|
-
<label className="inline-flex items-center gap-2 cursor-pointer">
|
|
5068
|
+
<label htmlFor={controlId} className="inline-flex items-center gap-2 cursor-pointer">
|
|
5007
5069
|
<Checkbox
|
|
5070
|
+
id={controlId}
|
|
5008
5071
|
checked={value === true}
|
|
5009
5072
|
onCheckedChange={(next) => setValue(field.id, next === true)}
|
|
5010
5073
|
data-crud-focus-target=""
|
|
@@ -5035,7 +5098,7 @@ const FieldControl = React.memo(function FieldControlImpl({
|
|
|
5035
5098
|
}}
|
|
5036
5099
|
disabled={disabled || readOnly}
|
|
5037
5100
|
>
|
|
5038
|
-
<SelectTrigger data-crud-focus-target="">
|
|
5101
|
+
<SelectTrigger id={controlId} data-crud-focus-target="">
|
|
5039
5102
|
<SelectValue placeholder={t('ui.forms.select.emptyOption', '—')}>
|
|
5040
5103
|
{singleSelectLabel}
|
|
5041
5104
|
</SelectValue>
|
|
@@ -5057,16 +5120,18 @@ const FieldControl = React.memo(function FieldControlImpl({
|
|
|
5057
5120
|
</Select>
|
|
5058
5121
|
)}
|
|
5059
5122
|
{field.type === 'select' && builtin?.multiple && builtin.listbox === true && (
|
|
5060
|
-
<
|
|
5061
|
-
|
|
5062
|
-
|
|
5063
|
-
|
|
5064
|
-
|
|
5065
|
-
|
|
5066
|
-
|
|
5123
|
+
<div role="group" aria-labelledby={labelId}>
|
|
5124
|
+
<ListboxMultiSelect
|
|
5125
|
+
options={options}
|
|
5126
|
+
placeholder={placeholder}
|
|
5127
|
+
value={Array.isArray(value) ? value.filter((item): item is string => typeof item === 'string') : []}
|
|
5128
|
+
onChange={(vals) => setValue(field.id, vals)}
|
|
5129
|
+
autoFocus={autoFocusField}
|
|
5130
|
+
/>
|
|
5131
|
+
</div>
|
|
5067
5132
|
)}
|
|
5068
5133
|
{field.type === 'select' && builtin?.multiple && builtin.listbox !== true && (
|
|
5069
|
-
<div className="flex flex-wrap gap-3">
|
|
5134
|
+
<div className="flex flex-wrap gap-3" role="group" aria-labelledby={labelId}>
|
|
5070
5135
|
{options.map((opt) => {
|
|
5071
5136
|
const arr = Array.isArray(value)
|
|
5072
5137
|
? value.filter((item): item is string => typeof item === 'string')
|
|
@@ -5094,22 +5159,24 @@ const FieldControl = React.memo(function FieldControlImpl({
|
|
|
5094
5159
|
</div>
|
|
5095
5160
|
)}
|
|
5096
5161
|
{field.type === 'relation' && (
|
|
5097
|
-
<
|
|
5098
|
-
|
|
5099
|
-
|
|
5100
|
-
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
|
|
5104
|
-
|
|
5105
|
-
|
|
5106
|
-
|
|
5107
|
-
|
|
5108
|
-
|
|
5109
|
-
|
|
5162
|
+
<div role="group" aria-labelledby={labelId}>
|
|
5163
|
+
<RelationSelect
|
|
5164
|
+
options={options}
|
|
5165
|
+
placeholder={placeholder}
|
|
5166
|
+
value={
|
|
5167
|
+
Array.isArray(value)
|
|
5168
|
+
? String(value[0] ?? '')
|
|
5169
|
+
: value == null
|
|
5170
|
+
? ''
|
|
5171
|
+
: String(value)
|
|
5172
|
+
}
|
|
5173
|
+
onChange={(selected) => setValue(field.id, selected)}
|
|
5174
|
+
autoFocus={autoFocusField}
|
|
5175
|
+
/>
|
|
5176
|
+
</div>
|
|
5110
5177
|
)}
|
|
5111
5178
|
{field.type === 'custom' && (
|
|
5112
|
-
|
|
5179
|
+
<div role="group" aria-labelledby={labelId}>
|
|
5113
5180
|
{field.component({
|
|
5114
5181
|
id: field.id,
|
|
5115
5182
|
value,
|
|
@@ -5122,7 +5189,7 @@ const FieldControl = React.memo(function FieldControlImpl({
|
|
|
5122
5189
|
autoFocus,
|
|
5123
5190
|
disabled,
|
|
5124
5191
|
})}
|
|
5125
|
-
|
|
5192
|
+
</div>
|
|
5126
5193
|
)}
|
|
5127
5194
|
{field.description ? (
|
|
5128
5195
|
<div className="flex items-start gap-2 text-xs text-muted-foreground">
|
|
@@ -5154,6 +5221,7 @@ const FieldControl = React.memo(function FieldControlImpl({
|
|
|
5154
5221
|
prev.wrapperClassName === next.wrapperClassName &&
|
|
5155
5222
|
prev.entityIdForField === next.entityIdForField &&
|
|
5156
5223
|
prev.recordId === next.recordId &&
|
|
5224
|
+
prev.formId === next.formId &&
|
|
5157
5225
|
(prev.field.type !== 'custom' ||
|
|
5158
5226
|
(prev.values === next.values &&
|
|
5159
5227
|
prev.field.component === (next.field as CrudCustomField).component &&
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/** @jest-environment jsdom */
|
|
2
|
+
jest.setTimeout(15000)
|
|
3
|
+
|
|
4
|
+
jest.mock('next/navigation', () => ({
|
|
5
|
+
useRouter: () => ({ push: () => {} }),
|
|
6
|
+
usePathname: () => '/',
|
|
7
|
+
useSearchParams: () => new URLSearchParams(),
|
|
8
|
+
}))
|
|
9
|
+
jest.mock('remark-gfm', () => ({ __esModule: true, default: {} }))
|
|
10
|
+
jest.mock('../injection/InjectionSpot', () => ({
|
|
11
|
+
__esModule: true,
|
|
12
|
+
InjectionSpot: () => null,
|
|
13
|
+
useInjectionWidgets: () => ({ widgets: [], loading: false, error: null }),
|
|
14
|
+
useInjectionSpotEvents: () => ({ triggerEvent: async () => ({ ok: true }) }),
|
|
15
|
+
}))
|
|
16
|
+
jest.mock('../injection/useInjectionDataWidgets', () => ({
|
|
17
|
+
__esModule: true,
|
|
18
|
+
useInjectionDataWidgets: () => ({ widgets: [], isLoading: false, error: null }),
|
|
19
|
+
}))
|
|
20
|
+
|
|
21
|
+
import * as React from 'react'
|
|
22
|
+
import { fireEvent } from '@testing-library/react'
|
|
23
|
+
import { renderWithProviders } from '@open-mercato/shared/lib/testing/renderWithProviders'
|
|
24
|
+
import { CrudForm, type CrudField } from '../CrudForm'
|
|
25
|
+
|
|
26
|
+
const dict = {
|
|
27
|
+
'ui.forms.actions.save': 'Save',
|
|
28
|
+
'ui.forms.select.emptyOption': '—',
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
describe('CrudForm accessible field labels (#5360)', () => {
|
|
32
|
+
it('associates a text field label with its input via htmlFor/id', () => {
|
|
33
|
+
const fields: CrudField[] = [{ id: 'displayName', label: 'Display name', type: 'text' }]
|
|
34
|
+
const { getByLabelText } = renderWithProviders(
|
|
35
|
+
<CrudForm title="Form" fields={fields} initialValues={{ displayName: '' }} onSubmit={() => {}} />,
|
|
36
|
+
{ dict },
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
const input = getByLabelText('Display name') as HTMLInputElement
|
|
40
|
+
expect(input.tagName).toBe('INPUT')
|
|
41
|
+
expect(input.id).toBeTruthy()
|
|
42
|
+
|
|
43
|
+
const label = document.querySelector(`label[for="${input.id}"]`) as HTMLLabelElement
|
|
44
|
+
expect(label).not.toBeNull()
|
|
45
|
+
fireEvent.click(label)
|
|
46
|
+
expect(document.activeElement).toBe(input)
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('associates a select field label with its trigger via htmlFor/id', () => {
|
|
50
|
+
const fields: CrudField[] = [
|
|
51
|
+
{
|
|
52
|
+
id: 'status',
|
|
53
|
+
label: 'Status',
|
|
54
|
+
type: 'select',
|
|
55
|
+
options: [{ value: 'open', label: 'Open' }, { value: 'closed', label: 'Closed' }],
|
|
56
|
+
},
|
|
57
|
+
]
|
|
58
|
+
const { getByLabelText } = renderWithProviders(
|
|
59
|
+
<CrudForm title="Form" fields={fields} initialValues={{ status: 'open' }} onSubmit={() => {}} />,
|
|
60
|
+
{ dict },
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
const trigger = getByLabelText('Status')
|
|
64
|
+
expect(trigger).not.toBeNull()
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('associates a checkbox field label with its control via htmlFor/id, and clicking the label toggles it', () => {
|
|
68
|
+
const onSubmit = jest.fn()
|
|
69
|
+
const fields: CrudField[] = [{ id: 'active', label: 'Active', type: 'checkbox' }]
|
|
70
|
+
const { getByLabelText } = renderWithProviders(
|
|
71
|
+
<CrudForm title="Form" fields={fields} initialValues={{ active: false }} onSubmit={onSubmit} />,
|
|
72
|
+
{ dict },
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
const checkbox = getByLabelText('Active') as HTMLElement
|
|
76
|
+
expect(checkbox).not.toBeNull()
|
|
77
|
+
expect(checkbox).toHaveAttribute('aria-checked', 'false')
|
|
78
|
+
|
|
79
|
+
const label = document.querySelector(`label[for="${checkbox.id}"]`) as HTMLLabelElement
|
|
80
|
+
expect(label).not.toBeNull()
|
|
81
|
+
fireEvent.click(label)
|
|
82
|
+
expect(checkbox).toHaveAttribute('aria-checked', 'true')
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('gives a custom field group an accessible name derived from its label (aria-labelledby fallback)', () => {
|
|
86
|
+
const fields: CrudField[] = [
|
|
87
|
+
{
|
|
88
|
+
id: 'notes',
|
|
89
|
+
label: 'Notes',
|
|
90
|
+
type: 'custom',
|
|
91
|
+
component: ({ value, setValue }) => (
|
|
92
|
+
<textarea
|
|
93
|
+
value={typeof value === 'string' ? value : ''}
|
|
94
|
+
onChange={(event) => setValue(event.target.value)}
|
|
95
|
+
/>
|
|
96
|
+
),
|
|
97
|
+
},
|
|
98
|
+
]
|
|
99
|
+
const { getByRole } = renderWithProviders(
|
|
100
|
+
<CrudForm title="Form" fields={fields} initialValues={{ notes: '' }} onSubmit={() => {}} />,
|
|
101
|
+
{ dict },
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
const group = getByRole('group', { name: 'Notes' })
|
|
105
|
+
expect(group).not.toBeNull()
|
|
106
|
+
expect(group.querySelector('textarea')).not.toBeNull()
|
|
107
|
+
})
|
|
108
|
+
})
|