File tree Expand file tree Collapse file tree 2 files changed +48
-1
lines changed
packages/vuetify/src/labs/VNumberInput Expand file tree Collapse file tree 2 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -75,7 +75,14 @@ export const VNumberInput = genericComponent<VNumberInputSlots>()({
75
75
const model = computed ( {
76
76
get : ( ) => _model . value ,
77
77
set ( val ) {
78
- if ( typeof val !== 'string' ) _model . value = val
78
+ if ( val === null ) {
79
+ _model . value = null
80
+ return
81
+ }
82
+
83
+ if ( ! isNaN ( + val ) && + val <= props . max && + val >= props . min ) {
84
+ _model . value = + val
85
+ }
79
86
} ,
80
87
} )
81
88
Original file line number Diff line number Diff line change @@ -42,6 +42,46 @@ describe('VNumberInput', () => {
42
42
expect ( model . value ) . equal ( null )
43
43
} )
44
44
} )
45
+
46
+ // https://github.com/vuetifyjs/vuetify/issues/20337
47
+ it ( 'should emit model-value when input value is a legit number within range of the max and min' , ( ) => {
48
+ const model = ref ( null )
49
+
50
+ cy . mount ( ( ) => (
51
+ < >
52
+ < VNumberInput
53
+ v-model = { model . value }
54
+ min = { 5 }
55
+ max = { 125 }
56
+ />
57
+ </ >
58
+ ) )
59
+ . get ( '.v-number-input input' )
60
+ . focus ( ) . realType ( '1' )
61
+ . then ( ( ) => {
62
+ expect ( model . value ) . equal ( null )
63
+ } )
64
+ . get ( '.v-number-input input' )
65
+ . realType ( '0' )
66
+ . then ( ( ) => {
67
+ expect ( model . value ) . equal ( 10 )
68
+ } )
69
+ . realType ( '0' )
70
+ . then ( ( ) => {
71
+ expect ( model . value ) . equal ( 100 )
72
+ } )
73
+ . realType ( '0' )
74
+ . get ( '.v-number-input input' )
75
+ . then ( ( ) => {
76
+ expect ( model . value ) . equal ( 100 )
77
+ } )
78
+ . get ( '.v-number-input input' )
79
+ . blur ( )
80
+ . then ( ( ) => {
81
+ expect ( model . value ) . equal ( 125 )
82
+ } )
83
+ } )
84
+
45
85
describe ( 'readonly' , ( ) => {
46
86
it ( 'should prevent mutation when readonly applied' , ( ) => {
47
87
const value = ref ( 1 )
You can’t perform that action at this time.
0 commit comments