From 96fca0763afbcd151ac7a2ec543c973debbb8089 Mon Sep 17 00:00:00 2001 From: Yauheni Vasiukevich Date: Sun, 15 Dec 2024 00:09:53 +0100 Subject: [PATCH] fix(VNumberInput): clearing v-number-input with backspace resets to 0 (#20729) Co-authored-by: Yuchao Wu --- .../src/labs/VNumberInput/VNumberInput.tsx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/vuetify/src/labs/VNumberInput/VNumberInput.tsx b/packages/vuetify/src/labs/VNumberInput/VNumberInput.tsx index 5e0a2835bbe..f3ee59cbe3b 100644 --- a/packages/vuetify/src/labs/VNumberInput/VNumberInput.tsx +++ b/packages/vuetify/src/labs/VNumberInput/VNumberInput.tsx @@ -74,14 +74,17 @@ export const VNumberInput = genericComponent()({ const model = computed({ get: () => _model.value, - set (val) { - if (val === null) { + // 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 } - 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 +297,9 @@ export const VNumberInput = genericComponent()({ { incrementControlNode() } - ) : (!props.reverse - ? <>{ dividerNode() }{ controlNode() } - : undefined) + ) : (props.reverse + ? undefined + : <>{ dividerNode() }{ controlNode() }) const hasAppendInner = slots['append-inner'] || appendInnerControl