@umituz/web-design-system 4.29.0 → 4.29.1
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/web-design-system",
|
|
3
|
-
"version": "4.29.
|
|
3
|
+
"version": "4.29.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Web Design System - Tailwind v4 authored, precompiled CSS shipped. Atomic Design components (Atoms, Molecules, Organisms, Templates) for React applications.",
|
|
@@ -1787,3 +1787,20 @@ describe('RatingStars (4.29)', () => {
|
|
|
1787
1787
|
expect(half).toBeTruthy();
|
|
1788
1788
|
});
|
|
1789
1789
|
});
|
|
1790
|
+
|
|
1791
|
+
import { FormField } from '../presentation/molecules/FormField';
|
|
1792
|
+
|
|
1793
|
+
describe('FormField auto id (4.29.1)', () => {
|
|
1794
|
+
it('links the label to a generated control id when none is given', () => {
|
|
1795
|
+
render(<FormField label="Reference" inputProps={{ placeholder: 'x' }} />);
|
|
1796
|
+
const control = screen.getByLabelText('Reference') as HTMLInputElement;
|
|
1797
|
+
expect(control.id).toBeTruthy();
|
|
1798
|
+
expect(control.getAttribute('aria-invalid')).toBe('false');
|
|
1799
|
+
});
|
|
1800
|
+
|
|
1801
|
+
it('describes the control through helper text ids', () => {
|
|
1802
|
+
render(<FormField label="Memo" helperText="Optional note" inputProps={{}} />);
|
|
1803
|
+
const control = screen.getByLabelText('Memo') as HTMLInputElement;
|
|
1804
|
+
expect((control.getAttribute('aria-describedby') ?? '').length).toBeGreaterThan(0);
|
|
1805
|
+
});
|
|
1806
|
+
});
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @description Label + Input combination (Responsive)
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { forwardRef } from 'react';
|
|
6
|
+
import { forwardRef, useId } from 'react';
|
|
7
7
|
import { cn, getSpaceY } from '../../infrastructure/utils';
|
|
8
8
|
import type { BaseProps } from '../../domain/types';
|
|
9
9
|
import { Input } from '../atoms/Input';
|
|
@@ -21,7 +21,8 @@ export interface FormFieldProps extends BaseProps {
|
|
|
21
21
|
|
|
22
22
|
export const FormField = forwardRef<HTMLInputElement, FormFieldProps>(
|
|
23
23
|
({ label, error, helperText, required, id, className, inputProps, fullWidth = true, ...props }, ref) => {
|
|
24
|
-
const
|
|
24
|
+
const autoId = useId();
|
|
25
|
+
const fieldId = id || inputProps?.id || inputProps?.name || autoId;
|
|
25
26
|
const errorId = error ? `${fieldId}-error` : undefined;
|
|
26
27
|
const helperId = helperText ? `${fieldId}-helper` : undefined;
|
|
27
28
|
|
|
@@ -38,7 +39,7 @@ export const FormField = forwardRef<HTMLInputElement, FormFieldProps>(
|
|
|
38
39
|
ref={ref}
|
|
39
40
|
id={fieldId}
|
|
40
41
|
aria-invalid={!!error}
|
|
41
|
-
aria-describedby={cn(errorId, helperId)}
|
|
42
|
+
aria-describedby={cn(errorId, helperId) || undefined}
|
|
42
43
|
error={!!error}
|
|
43
44
|
{...inputProps}
|
|
44
45
|
/>
|