Skip to content

Commit 5ac1587

Browse files
authored
Fix Uncontrolled Component Issue
This fixes an issue where React says that an uncontrolled component is switching to a controlled component.
1 parent 8a82783 commit 5ac1587

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

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)