Skip to content
This repository was archived by the owner on Jul 25, 2022. It is now read-only.

Commit 848bc37

Browse files
committed
fix #3 issue
1 parent e926c16 commit 848bc37

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ For more detailed example check out [the app directory](./app).
6161
## Attributes
6262

6363
- __step:__ Step value for increment and decrement the input number value.
64-
- __min:__ Minimum value for input number.
64+
- __min:__ Minimum value for input number. `min` is only used as a placeholder if `placeholder` is empty.
6565
- __max:__ Maximum value for input number.
6666
- __maxlength:__ Maxlength for the input number.
6767
- __keydown:__ Enable keydown for increment or decrement value.
6868
- __mousedown:__ Enable mousedown for increment or decrement value.
6969
- __integer:__ Enable integer value only.
70-
- __placeholder:__ Set a input placeholder.
70+
- __placeholder:__ Set a input placeholder. If `placeholder` has some value then `min` is not used as a placeholder.
7171

7272
## Events
7373

index.vue

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,19 @@ export default {
7676
},
7777
7878
watch: {
79+
placeholder: function () {
80+
this.quantity = !this.placeholder ? this.min : null
81+
},
7982
quantity: function () {
8083
this.evaluateQuantity()
8184
},
8285
min: function (val) {
83-
if (this.quantity < val) this.quantity = val
86+
if (this.quantity < val) {
87+
this.quantity = val
88+
}
8489
},
8590
max: function (val) {
86-
if (this.quantity > val) this.quantity = val
87-
else this.quantity = this.min
91+
this.quantity = this.quantity > val ? val : this.min
8892
}
8993
},
9094
@@ -99,23 +103,39 @@ export default {
99103
100104
emitChange (init = false) {
101105
this.oldValue = this.quantity
102-
if (init) this.quantity = this.min
106+
107+
if (init && !this.placeholder) {
108+
this.quantity = this.min
109+
}
110+
103111
this.$emit('onInputNumberChange', this.quantity, init)
104112
},
105113
106114
increment () {
107-
this.quantity = this.quantity < this.max
108-
? this.quantity + this.step
109-
: this.max
115+
if (!this.quantity) {
116+
this.quantity = this.min
117+
} else {
118+
this.quantity = this.quantity < this.max
119+
? this.quantity + this.step
120+
: this.max
121+
}
110122
},
111123
112124
decrement () {
113-
this.quantity = this.quantity > this.min
114-
? this.quantity - this.step
115-
: this.min
125+
if (!this.quantity) {
126+
this.quantity = this.min
127+
} else {
128+
this.quantity = this.quantity > this.min
129+
? this.quantity - this.step
130+
: this.min
131+
}
116132
},
117133
118134
onBlur () {
135+
if (this.placeholder && !this.quantity) {
136+
return
137+
}
138+
119139
if (this.quantity.toString().length === 0) {
120140
this.quantity = this.oldValue
121141
return
@@ -141,6 +161,7 @@ export default {
141161
if (this.isKeydown) return
142162
143163
if (
164+
!this.placeholder &&
144165
this.quantity.toString().length > 0 &&
145166
this.quantity !== this.oldValue
146167
) {

0 commit comments

Comments
 (0)