From 55208ae920674e6864d87b856b1b37f0822cbffa Mon Sep 17 00:00:00 2001 From: EvgenyWas Date: Sun, 24 Nov 2024 14:41:52 +0000 Subject: [PATCH 1/2] fix(VNumberInput): expect empty string on reset to perform validation --- .../src/labs/VNumberInput/VNumberInput.tsx | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/vuetify/src/labs/VNumberInput/VNumberInput.tsx b/packages/vuetify/src/labs/VNumberInput/VNumberInput.tsx index bbf59a65c74..3e2223834b2 100644 --- a/packages/vuetify/src/labs/VNumberInput/VNumberInput.tsx +++ b/packages/vuetify/src/labs/VNumberInput/VNumberInput.tsx @@ -75,13 +75,14 @@ export const VNumberInput = genericComponent()({ const model = computed({ get: () => _model.value, set (val) { - if (val === null) { - _model.value = null + if (val === null || (typeof val === 'string' && !val)) { + _model.value = val return } - if (!isNaN(+val) && +val <= props.max && +val >= props.min) { - _model.value = +val + const value = Number(val) + if (!isNaN(value) && value <= props.max && value >= props.min) { + _model.value = value } }, }) @@ -294,9 +295,9 @@ export const VNumberInput = genericComponent()({ { incrementControlNode() } - ) : (!props.reverse - ? <>{ dividerNode() }{ controlNode() } - : undefined) + ) : (props.reverse + ? undefined + : <>{ dividerNode() }{ controlNode() }) const hasAppendInner = slots['append-inner'] || appendInnerControl From 6a5599096f68579334c8f1f4ebcecccb0a295719 Mon Sep 17 00:00:00 2001 From: Yuchao Wu Date: Thu, 12 Dec 2024 23:55:13 +1100 Subject: [PATCH 2/2] refactor: keep _model.value as null when assigning empty string --- packages/vuetify/src/labs/VNumberInput/VNumberInput.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/vuetify/src/labs/VNumberInput/VNumberInput.tsx b/packages/vuetify/src/labs/VNumberInput/VNumberInput.tsx index e1c0a4af5d3..f3ee59cbe3b 100644 --- a/packages/vuetify/src/labs/VNumberInput/VNumberInput.tsx +++ b/packages/vuetify/src/labs/VNumberInput/VNumberInput.tsx @@ -74,9 +74,11 @@ export const VNumberInput = genericComponent()({ const model = computed({ get: () => _model.value, - set (val) { - if (val === null || (typeof val === 'string' && !val)) { - _model.value = val + // model.value could be empty string from VTextField + // but _model.value should be eventually kept in type Number | null + set (val: Number | null | string) { + if (val === null || val === '') { + _model.value = null return }