@@ -16,40 +16,20 @@ export default function FieldError<T>({
1616
1717 if ( Array . isArray ( fieldErrors ) ) {
1818 return (
19- < div
20- className = "fr-messages-group"
19+ < ErrorMessage
2120 id = { `participation-${ String ( firstKey ) } -messages` }
22- aria-live = "polite"
23- >
24- { fieldErrors . map ( ( errorMsg , idx ) => (
25- < p
26- className = "fr-message fr-message--error"
27- key = { `participation-${ String ( firstKey ) } -error-${ idx } ` }
28- >
29- { errorMsg }
30- </ p >
31- ) ) }
32- </ div >
21+ errors = { fieldErrors }
22+ />
3323 ) ;
3424 }
3525
3626 if ( ! secondKey ) {
3727 if ( "non_field_errors" in fieldErrors ) {
3828 return (
39- < div
40- className = "fr-messages-group"
29+ < ErrorMessage
4130 id = { `participation-${ String ( firstKey ) } -messages` }
42- aria-live = "polite"
43- >
44- { fieldErrors . non_field_errors . map ( ( errorMsg , idx ) => (
45- < p
46- className = "fr-message fr-message--error"
47- key = { `participation-${ String ( firstKey ) } -non-field-error-${ idx } ` }
48- >
49- { errorMsg }
50- </ p >
51- ) ) }
52- </ div >
31+ errors = { fieldErrors . non_field_errors }
32+ />
5333 ) ;
5434 }
5535 return null ;
@@ -66,21 +46,23 @@ export default function FieldError<T>({
6646
6747 if ( Array . isArray ( secondFieldErrors ) ) {
6848 return (
69- < div
70- className = "fr-messages-group"
49+ < ErrorMessage
7150 id = { `participation-${ String ( firstKey ) } -${ String ( secondKey ) } -messages` }
72- aria-live = "polite"
73- >
74- { secondFieldErrors . map ( ( errorMsg , idx ) => (
75- < p
76- className = "fr-message fr-message--error"
77- key = { `participation-${ String ( firstKey ) } -${ String ( secondKey ) } -error-${ idx } ` }
78- >
79- { errorMsg }
80- </ p >
81- ) ) }
82- </ div >
51+ errors = { secondFieldErrors }
52+ />
8353 ) ;
8454 }
8555 }
8656}
57+
58+ export function ErrorMessage ( { id, errors } : { id : string ; errors : string [ ] } ) {
59+ return (
60+ < div className = "fr-messages-group" id = { id } aria-live = "polite" >
61+ { errors . map ( ( errorMsg , idx ) => (
62+ < p className = "fr-message fr-message--error" key = { `${ id } -error-${ idx } ` } >
63+ { errorMsg }
64+ </ p >
65+ ) ) }
66+ </ div >
67+ ) ;
68+ }
0 commit comments