[Improvement] Stepper: add interger prop (#951)

This commit is contained in:
neverland
2018-04-27 22:57:28 +08:00
committed by GitHub
parent e25f98540d
commit fa8f88c7be
4 changed files with 39 additions and 25 deletions

View File

@@ -10,6 +10,7 @@
:value="currentValue"
:disabled="disabled || disableInput"
@input="onInput"
@keypress="onKeypress"
>
<button
:class="b('plus', { disabled: plusDisabled })"
@@ -26,6 +27,7 @@ export default create({
props: {
value: {},
interger: Boolean,
disabled: Boolean,
disableInput: Boolean,
min: {
@@ -88,14 +90,9 @@ export default create({
methods: {
correctValue(value) {
if (Number.isNaN(value)) {
value = this.min;
} else {
value = Math.max(this.min, value);
value = Math.min(this.max, value);
}
return value;
return Number.isNaN(value)
? this.min
: Math.max(this.min, Math.min(this.max, value));
},
onInput(event) {
@@ -118,6 +115,12 @@ export default create({
this.$emit(type);
},
onKeypress(event) {
if (this.interger && event.keyCode === 46) {
event.preventDefault();
}
},
emitInput() {
this.$emit('input', this.currentValue);
this.$emit('change', this.currentValue);