Skip to content

Commit

Permalink
fix(VNumberInput): clearing v-number-input with backspace resets to 0 (
Browse files Browse the repository at this point in the history
…#20729)

Co-authored-by: Yuchao Wu <[email protected]>
  • Loading branch information
EvgenyWas and yuwu9145 authored Dec 14, 2024
1 parent 89c58dd commit 96fca07
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions packages/vuetify/src/labs/VNumberInput/VNumberInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,17 @@ export const VNumberInput = genericComponent<VNumberInputSlots>()({

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
}
},
})
Expand Down Expand Up @@ -294,9 +297,9 @@ export const VNumberInput = genericComponent<VNumberInputSlots>()({

{ incrementControlNode() }
</div>
) : (!props.reverse
? <>{ dividerNode() }{ controlNode() }</>
: undefined)
) : (props.reverse
? undefined
: <>{ dividerNode() }{ controlNode() }</>)

const hasAppendInner = slots['append-inner'] || appendInnerControl

Expand Down

0 comments on commit 96fca07

Please sign in to comment.