@@ -8,9 +8,9 @@ import React, {
88 SyntheticEvent ,
99} from 'react' ;
1010import classNames from 'classnames' ;
11- import ErrorMessage from '../error-message ' ;
12- import Hint from '../hint ' ;
13- import Label from '../label ' ;
11+ import { FormElementProps } from '../../util/types/FormTypes ' ;
12+ import { generateRandomName } from '../../util/RandomName ' ;
13+ import LabelBlock from '../../util/LabelBlock ' ;
1414
1515interface IDateInputContext {
1616 isDateInput : boolean ;
@@ -96,15 +96,15 @@ DateInputInput.defaultProps = {
9696 pattern : '[0-9]*' ,
9797} ;
9898
99- const DateInputDay : React . FC < HTMLProps < HTMLInputElement > > = props => (
99+ const DateInputDay : React . FC < Omit < DateInputInputProps , 'dateInputType' > > = props => (
100100 < DateInputInput dateInputType = "Day" { ...props } />
101101) ;
102102
103- const DateInputMonth : React . FC < HTMLProps < HTMLInputElement > > = props => (
103+ const DateInputMonth : React . FC < Omit < DateInputInputProps , 'dateInputType' > > = props => (
104104 < DateInputInput dateInputType = "Month" { ...props } />
105105) ;
106106
107- const DateInputYear : React . FC < HTMLProps < HTMLInputElement > > = props => (
107+ const DateInputYear : React . FC < Omit < DateInputInputProps , 'dateInputType' > > = props => (
108108 < DateInputInput dateInputType = "Year" { ...props } />
109109) ;
110110
@@ -123,13 +123,10 @@ type DateInputValue = {
123123 year : string ;
124124} ;
125125
126- interface DateInputProps extends Omit < HTMLProps < HTMLDivElement > , 'onChange' > {
126+ interface DateInputProps extends Omit < HTMLProps < HTMLDivElement > , 'onChange' > , FormElementProps {
127127 autoSelectNext ?: boolean ;
128128 onChange ?: ( e : DateInputEvent ) => any ;
129129 autoCompletePrefix ?: string ;
130- error ?: string ;
131- hint ?: string ;
132- labelHtmlFor ?: string ;
133130}
134131
135132type DateInputState = {
@@ -146,7 +143,7 @@ class DateInput extends PureComponent<DateInputProps, DateInputState> {
146143 constructor ( props : DateInputProps , ...rest : any [ ] ) {
147144 super ( props , ...rest ) ;
148145 this . state = {
149- name : props . name || `dateinput_ ${ ( Math . random ( ) + 1 ) . toString ( 36 ) . substring ( 2 , 7 ) } ` ,
146+ name : props . name || generateRandomName ( 'dateinput' ) ,
150147 value : { day : '' , month : '' , year : '' } ,
151148 } ;
152149 this . monthRef = null ;
@@ -211,10 +208,12 @@ class DateInput extends PureComponent<DateInputProps, DateInputState> {
211208 children,
212209 autoSelectNext,
213210 autoCompletePrefix,
214- labelHtmlFor,
215211 hint,
216212 error,
217213 label,
214+ labelProps,
215+ errorProps,
216+ hintProps,
218217 ...rest
219218 } = this . props ;
220219 const { name } = this . state ;
@@ -228,13 +227,20 @@ class DateInput extends PureComponent<DateInputProps, DateInputState> {
228227
229228 return (
230229 < >
231- { label ? < Label htmlFor = { labelHtmlFor || id } > { label } </ Label > : null }
232- { hint ? < Hint > { hint } </ Hint > : null }
233- { error ? < ErrorMessage > { error } </ ErrorMessage > : null }
230+ < LabelBlock
231+ elementId = { id }
232+ label = { label }
233+ labelProps = { labelProps }
234+ hint = { hint }
235+ hintProps = { hintProps }
236+ error = { error }
237+ errorProps = { errorProps }
238+ />
234239 < div
240+ id = { id }
235241 className = { classNames ( 'nhsuk-date-input' , className ) }
236- { ...rest }
237242 onChange = { this . onChange }
243+ { ...rest }
238244 >
239245 < DateInputContext . Provider value = { contextValue } >
240246 { children || (
0 commit comments