Skip to content

Commit 6034a73

Browse files
committed
fix(VNumberInput): apply pasted value without waiting for blur
fixes #22182 closes #22222
1 parent 75b45a6 commit 6034a73

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ export const VNumberInput = genericComponent<VNumberInputSlots>()({
245245
if (!new RegExp(`^-?\\d*${escapeForRegex(decimalSeparator.value)}?\\d*$`).test(potentialNewInputVal)) {
246246
e.preventDefault()
247247
inputElement!.value = potentialNewNumber
248+
nextTick(() => inputText.value = potentialNewNumber)
248249
}
249250

250251
if (props.precision == null) return
@@ -253,14 +254,16 @@ export const VNumberInput = genericComponent<VNumberInputSlots>()({
253254
if (potentialNewInputVal.split(decimalSeparator.value)[1]?.length > props.precision) {
254255
e.preventDefault()
255256
inputElement!.value = potentialNewNumber
257+
nextTick(() => inputText.value = potentialNewNumber)
256258

257259
const cursorPosition = (selectionStart ?? 0) + e.data.length
258260
inputElement!.setSelectionRange(cursorPosition, cursorPosition)
259261
}
260262
// Ignore decimal separator when precision = 0
261-
if (props.precision === 0 && potentialNewInputVal.includes(decimalSeparator.value)) {
263+
if (props.precision === 0 && potentialNewInputVal.endsWith(decimalSeparator.value)) {
262264
e.preventDefault()
263265
inputElement!.value = potentialNewNumber
266+
nextTick(() => inputText.value = potentialNewNumber)
264267
}
265268
}
266269

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ describe('VNumberInput', () => {
253253
{ precision: 1, text: '200.99', expected: 200.9 },
254254
{ precision: 2, text: ' 1,250.32\n', expected: 1250.32 },
255255
{ precision: 0, text: '1\'024.00 meters', expected: 1024 },
256-
{ precision: 0, text: '- 1123.', expected: -1123 },
256+
{ precision: 0, text: '-1123.', expected: -1123 },
257257
])('should parse numbers correctly', async ({ precision, text, expected }) => {
258258
const model = ref(null)
259259
const { element } = render(() => (
@@ -266,7 +266,6 @@ describe('VNumberInput', () => {
266266
input.focus()
267267
navigator.clipboard.writeText(text)
268268
await userEvent.paste()
269-
input.blur()
270269
expect(model.value).toBe(expected)
271270
})
272271

0 commit comments

Comments
 (0)