From fb2cd500f6c6c86a3d6035911dd503e5e3c90dbc Mon Sep 17 00:00:00 2001 From: Moleesh Date: Tue, 25 Apr 2023 16:41:26 +0530 Subject: [PATCH 1/4] if the value is 0 don't focus the next field. --- src/DateInput.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/DateInput.tsx b/src/DateInput.tsx index b0774f11..3b4dbc83 100644 --- a/src/DateInput.tsx +++ b/src/DateInput.tsx @@ -422,8 +422,9 @@ export default function DateInput({ * 10 would be a valid value given max = 12, so we won't jump to the next input. * However, given 2, smallers possible number would be 20, and thus keeping the focus in * this field doesn't make sense. + * if the value is 0 don't focus the next field. */ - if (Number(value) * 10 > Number(max) || value.length >= max.length) { + if (Number(value) && (Number(value) * 10 > Number(max) || value.length >= max.length)) { const property = 'nextElementSibling'; const nextInput = findInput(input, property); focus(nextInput); From 2cafa0b42d4e7e033c0d1c17e1a5d0dce5a5b9ff Mon Sep 17 00:00:00 2001 From: Moleesh Date: Tue, 25 Apr 2023 16:44:36 +0530 Subject: [PATCH 2/4] if the value is 0 don't focus the next field. --- src/DateInput.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/DateInput.tsx b/src/DateInput.tsx index 3b4dbc83..cc51427e 100644 --- a/src/DateInput.tsx +++ b/src/DateInput.tsx @@ -422,7 +422,6 @@ export default function DateInput({ * 10 would be a valid value given max = 12, so we won't jump to the next input. * However, given 2, smallers possible number would be 20, and thus keeping the focus in * this field doesn't make sense. - * if the value is 0 don't focus the next field. */ if (Number(value) && (Number(value) * 10 > Number(max) || value.length >= max.length)) { const property = 'nextElementSibling'; From 2903664bc23333b7a1477b0e9b24dc127bd8064f Mon Sep 17 00:00:00 2001 From: Moleesh Date: Tue, 25 Apr 2023 17:23:28 +0530 Subject: [PATCH 3/4] remove the padding zeros --- src/DateInput.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/DateInput.tsx b/src/DateInput.tsx index cc51427e..8b895d79 100644 --- a/src/DateInput.tsx +++ b/src/DateInput.tsx @@ -485,16 +485,17 @@ export default function DateInput({ event: React.ChangeEvent | React.ChangeEvent, ) { const { name, value } = event.target; + const correctedValue = value && parseInt(value, 10).toString() switch (name) { case 'year': - setYear(value); + setYear(correctedValue); break; case 'month': - setMonth(value); + setMonth(correctedValue); break; case 'day': - setDay(value); + setDay(correctedValue); break; } From 1783c563061612fa9386203499394304d8c073cd Mon Sep 17 00:00:00 2001 From: Moleesh Date: Tue, 25 Apr 2023 17:23:44 +0530 Subject: [PATCH 4/4] typo --- src/DateInput.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DateInput.tsx b/src/DateInput.tsx index 8b895d79..792f97b9 100644 --- a/src/DateInput.tsx +++ b/src/DateInput.tsx @@ -485,7 +485,7 @@ export default function DateInput({ event: React.ChangeEvent | React.ChangeEvent, ) { const { name, value } = event.target; - const correctedValue = value && parseInt(value, 10).toString() + const correctedValue = value && parseInt(value, 10).toString(); switch (name) { case 'year':