Skip to content

Commit ca5741f

Browse files
authored
Merge pull request #27 from NHSDigital/feature/tjc-patch-date-input
Fix Uncontrolled Component Issue
2 parents 8a82783 + ff62c26 commit ca5741f

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/components/date-input/__tests__/__snapshots__/DateInput.test.tsx.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ exports[`DateInput matches snapshot 1`] = `
2121
<IndividualDateInput
2222
inputType="day"
2323
pattern="[0-9]*"
24+
type="number"
2425
>
2526
<div
2627
className="nhsuk-date-input__item"
@@ -54,6 +55,7 @@ exports[`DateInput matches snapshot 1`] = `
5455
name="testInput-day"
5556
onChange={[Function]}
5657
pattern="[0-9]*"
58+
type="number"
5759
/>
5860
</div>
5961
</div>
@@ -63,6 +65,7 @@ exports[`DateInput matches snapshot 1`] = `
6365
<IndividualDateInput
6466
inputType="month"
6567
pattern="[0-9]*"
68+
type="number"
6669
>
6770
<div
6871
className="nhsuk-date-input__item"
@@ -96,6 +99,7 @@ exports[`DateInput matches snapshot 1`] = `
9699
name="testInput-month"
97100
onChange={[Function]}
98101
pattern="[0-9]*"
102+
type="number"
99103
/>
100104
</div>
101105
</div>
@@ -105,6 +109,7 @@ exports[`DateInput matches snapshot 1`] = `
105109
<IndividualDateInput
106110
inputType="year"
107111
pattern="[0-9]*"
112+
type="number"
108113
>
109114
<div
110115
className="nhsuk-date-input__item"
@@ -138,6 +143,7 @@ exports[`DateInput matches snapshot 1`] = `
138143
name="testInput-year"
139144
onChange={[Function]}
140145
pattern="[0-9]*"
146+
type="number"
141147
/>
142148
</div>
143149
</div>

src/components/date-input/components/IndividualDateInputs.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ const IndividualDateInput: React.FC<IndividualDateInputProps> = ({
4444

4545
const inputID = id || `${ctxId}-${inputType}`;
4646
const inputName = name || `${ctxName}-${inputType}`;
47-
const inputValue = value || ctxValue?.[inputType] || undefined;
48-
const inputDefaultValue = defaultValue || ctxDefaultValue?.[inputType] || undefined;
47+
const inputValue = value !== undefined ? value : ctxValue?.[inputType];
48+
const inputDefaultValue = defaultValue !== undefined ? defaultValue : ctxDefaultValue?.[inputType];
4949

5050
const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
5151
e.persist();
@@ -95,6 +95,7 @@ const IndividualDateInput: React.FC<IndividualDateInputProps> = ({
9595

9696
IndividualDateInput.defaultProps = {
9797
pattern: '[0-9]*',
98+
type: 'number',
9899
};
99100

100101
export const DayInput: React.FC<Omit<IndividualDateInputProps, 'inputType'>> = props => (

0 commit comments

Comments
 (0)