Skip to content

Commit ab2d941

Browse files
committed
fix(VNumberInput): only trim zeros from the end
fixes #21828
1 parent 0a3c710 commit ab2d941

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

packages/vuetify/src/components/VNumberInput/VNumberInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export const VNumberInput = genericComponent<VNumberInputSlots>()({
115115
let [baseDigits, fractionDigits] = fixed.split('.')
116116

117117
fractionDigits = (fractionDigits ?? '').padEnd(props.minFractionDigits, '0')
118-
.replace(new RegExp(`(?<=\\d{${props.minFractionDigits}})0`, 'g'), '')
118+
.replace(new RegExp(`(?<=\\d{${props.minFractionDigits}})0+$`, 'g'), '')
119119

120120
return [
121121
baseDigits,

packages/vuetify/src/components/VNumberInput/__tests__/VNumberInput.spec.browser.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,26 @@ describe('VNumberInput', () => {
296296
input.blur()
297297
expect(model.value).toBe(expected)
298298
})
299+
300+
// https://github.com/vuetifyjs/vuetify/issues/21828
301+
it('should only trim values from the end', async () => {
302+
const model = ref(0.01)
303+
render(() => (
304+
<VNumberInput
305+
v-model={ model.value }
306+
minFractionDigits={ 0 }
307+
precision={ 4 }
308+
/>
309+
))
310+
311+
await userEvent.click(screen.getByCSS('input'))
312+
expect(screen.getByCSS('input')).toHaveValue('0.01')
313+
314+
await userEvent.keyboard('{backspace}2')
315+
await userEvent.tab()
316+
expect(screen.getByCSS('input')).toHaveValue('0.02')
317+
expect(model.value).toBe(0.02)
318+
})
299319
})
300320

301321
describe('fraction digits control', () => {

0 commit comments

Comments
 (0)