@@ -32,9 +32,21 @@ const DatepickerControl = ({
3232 [ DATEPICKER_TYPES . date ] : DATE_FORMAT ,
3333 [ DATEPICKER_TYPES . time ] : TIME_FORMAT ,
3434 } ;
35+ const isTimePicker = type === DATEPICKER_TYPES . time ;
36+
37+ let describedByIds ;
38+ if ( isTimePicker ) {
39+ const ids = [ `${ controlName } -timehint` ] ;
40+ if ( helpText ) {
41+ ids . push ( `${ controlName } -helptext` ) ;
42+ }
43+ describedByIds = ids . filter ( Boolean ) . join ( ' ' ) || undefined ;
44+ } else if ( helpText ) {
45+ describedByIds = `${ controlName } -helptext` ;
46+ }
3547
3648 return (
37- < Form . Group className = "form-group-custom datepicker-custom" >
49+ < Form . Group controlId = { controlName } className = "form-group-custom datepicker-custom" >
3850 < Form . Label className = "d-flex justify-content-between" >
3951 { label }
4052 { showUTC && (
@@ -52,6 +64,7 @@ const DatepickerControl = ({
5264 />
5365 ) }
5466 < DatePicker
67+ id = { controlName }
5568 name = { controlName }
5669 selected = { formattedDate }
5770 disabled = { readonly }
@@ -67,14 +80,26 @@ const DatepickerControl = ({
6780 showTimeSelectOnly = { type === DATEPICKER_TYPES . time }
6881 placeholderText = { inputFormat [ type ] . toLocaleUpperCase ( ) }
6982 showPopperArrow = { false }
83+ aria-describedby = { describedByIds }
7084 onChange = { ( date ) => {
7185 if ( isValidDate ( date ) ) {
7286 onChange ( convertToStringFromDate ( date ) ) ;
7387 }
7488 } }
7589 />
7690 </ div >
77- { helpText && < Form . Control . Feedback > { helpText } </ Form . Control . Feedback > }
91+ { isTimePicker && (
92+ < Form . Text id = { `${ controlName } -timehint` } className = "sr-only" >
93+ { intl . formatMessage ( messages . timepickerScreenreaderHint , {
94+ timeFormat : inputFormat [ type ] . toLocaleUpperCase ( ) ,
95+ } ) }
96+ </ Form . Text >
97+ ) }
98+ { helpText && (
99+ < Form . Control . Feedback id = { `${ controlName } -helptext` } >
100+ { helpText }
101+ </ Form . Control . Feedback >
102+ ) }
78103 </ Form . Group >
79104 ) ;
80105} ;
0 commit comments