Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(VNumberInput): clearing v-number-input with backspace resets to 0 #20729

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

@yuwu9145 yuwu9145 Dec 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change just a code format? Or was there any logically concrete reason behind it? @EvgenyWas

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only code format to remove the exclamation mark. I believe it's easier to read especially when there is the same condition with another case.

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

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

Expand Down
Loading