File tree Expand file tree Collapse file tree 4 files changed +18
-7
lines changed Expand file tree Collapse file tree 4 files changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,10 @@ export const FieldRadioGroup = <
66
66
< RadioGroup
67
67
id = { ctx . id }
68
68
aria-invalid = { fieldState . error ? true : undefined }
69
+ /**
70
+ * RadioGroup is a div with role `radiogroup`. the label's `for` is not working and we need to explicitly set the ARIA attribute.
71
+ */
72
+ aria-labelledby = { ctx . labelId }
69
73
aria-describedby = {
70
74
! fieldState . error
71
75
? `${ ctx . descriptionId } `
@@ -76,9 +80,11 @@ export const FieldRadioGroup = <
76
80
{ ...field }
77
81
>
78
82
{ options . map ( ( { label, ...option } ) => {
83
+ const radioId = `${ ctx . id } -${ option . value } ` ;
84
+
79
85
if ( renderOption ) {
80
86
return (
81
- < React . Fragment key = { ` ${ ctx . id } - ${ option . value } ` } >
87
+ < React . Fragment key = { radioId } >
82
88
{ renderOption ( {
83
89
label,
84
90
onBlur,
@@ -89,11 +95,7 @@ export const FieldRadioGroup = <
89
95
}
90
96
91
97
return (
92
- < Radio
93
- key = { `${ ctx . id } -${ option . value } ` }
94
- onBlur = { onBlur }
95
- { ...option }
96
- >
98
+ < Radio key = { radioId } onBlur = { onBlur } { ...option } >
97
99
{ label }
98
100
</ Radio >
99
101
) ;
Original file line number Diff line number Diff line change @@ -2,12 +2,16 @@ import { ComponentProps } from 'react';
2
2
3
3
import { cn } from '@/lib/tailwind/utils' ;
4
4
5
+ import { useFormField } from '@/components/form/form-field' ;
6
+
5
7
export const FormFieldHelper = ( {
6
8
className,
7
9
...props
8
10
} : ComponentProps < 'div' > ) => {
11
+ const ctx = useFormField ( ) ;
9
12
return (
10
13
< div
14
+ id = { ctx . descriptionId }
11
15
className = { cn ( 'text-xs text-muted-foreground' , className ) }
12
16
{ ...props }
13
17
/>
Original file line number Diff line number Diff line change @@ -4,7 +4,9 @@ import { cn } from '@/lib/tailwind/utils';
4
4
5
5
import { useFormField } from './form-field' ;
6
6
7
- type FormFieldLabelProps = ComponentProps < 'label' > ;
7
+ type FormFieldLabelProps = ComponentProps < 'label' > & {
8
+ asDiv ?: boolean ;
9
+ } ;
8
10
9
11
export const FormFieldLabel = ( {
10
12
className,
@@ -13,6 +15,7 @@ export const FormFieldLabel = ({
13
15
const ctx = useFormField ( ) ;
14
16
return (
15
17
< label
18
+ id = { ctx . labelId }
16
19
htmlFor = { ctx . id }
17
20
className = { cn ( 'flex gap-1.5 align-baseline text-sm' , className ) }
18
21
{ ...props }
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ export const FormField = (props: FormFieldProps) => {
18
18
const contextValue = useMemo (
19
19
( ) => ( {
20
20
id,
21
+ labelId : `${ id } -label` ,
21
22
descriptionId : `${ id } -description` ,
22
23
errorId : `${ id } -error` ,
23
24
size : props . size ,
@@ -36,6 +37,7 @@ export const FormField = (props: FormFieldProps) => {
36
37
37
38
type FormFieldContextValue = {
38
39
id : string ;
40
+ labelId : string ;
39
41
descriptionId : string ;
40
42
errorId : string ;
41
43
size ?: FormFieldSize ;
You can’t perform that action at this time.
0 commit comments