@@ -7,11 +7,19 @@ import React, {
77 RefAttributes ,
88} from 'react' ;
99import classNames from 'classnames' ;
10+ import useDevWarning from '@util/hooks/UseDevWarning' ;
1011
11- const ErrorSummaryTitle : FC < HTMLProps < HTMLHeadingElement > > = ( { className, ...rest } ) => (
12- < h2 className = { classNames ( 'nhsuk-error-summary__title' , className ) } { ...rest } />
12+ const DefaultErrorSummaryTitleID = 'error-summary-title' ;
13+
14+ const ErrorSummaryTitle : FC < HTMLProps < HTMLHeadingElement > > = ( {
15+ className,
16+ id = DefaultErrorSummaryTitleID ,
17+ ...rest
18+ } ) => (
19+ < h2 className = { classNames ( 'nhsuk-error-summary__title' , className ) } id = { id } { ...rest } />
1320) ;
1421
22+
1523const ErrorSummaryBody : FC < HTMLProps < HTMLDivElement > > = ( { className, ...rest } ) => (
1624 < div className = { classNames ( 'nhsuk-error-summary__body' , className ) } { ...rest } />
1725) ;
@@ -37,10 +45,31 @@ interface ErrorSummary
3745}
3846
3947const ErrorSummaryDiv = forwardRef < HTMLDivElement , HTMLProps < HTMLDivElement > > (
40- ( { className, ...rest } , ref ) => (
41- < div className = { classNames ( 'nhsuk-error-summary' , className ) } ref = { ref } { ...rest } />
42- ) ,
43- ) ;
48+ ( {
49+ className,
50+ tabIndex = - 1 ,
51+ role = 'alert' ,
52+ 'aria-labelledby' : ariaLabelledBy = DefaultErrorSummaryTitleID ,
53+ ...rest
54+ } ,
55+ ref
56+ ) => {
57+ useDevWarning ( 'The ErrorSummary component should always have a tabIndex of -1' , ( ) => tabIndex !== - 1 )
58+ useDevWarning ( 'The ErrorSummary component should always have a role of alert' , ( ) => role !== 'alert' )
59+
60+ return (
61+ < div
62+ className = { classNames ( 'nhsuk-error-summary' , className ) }
63+ ref = { ref }
64+ tabIndex = { tabIndex }
65+ role = { role }
66+ aria-labelledby = { ariaLabelledBy }
67+ { ...rest }
68+ />
69+ )
70+ } ) ;
71+
72+
4473ErrorSummaryDiv . displayName = 'ErrorSummary' ;
4574
4675const ErrorSummary : ErrorSummary = Object . assign ( ErrorSummaryDiv , {
0 commit comments