diff --git a/packages/devui-vue/devui/input-number/src/input-number.scss b/packages/devui-vue/devui/input-number/src/input-number.scss index 44ede7ae04..804161f15c 100644 --- a/packages/devui-vue/devui/input-number/src/input-number.scss +++ b/packages/devui-vue/devui/input-number/src/input-number.scss @@ -46,26 +46,29 @@ } &.devui-input-number-sm { - .devui-input-box{ - width: 80px; + width: 60px; + + .devui-input-box { height: 26px; line-height: 26px; } } - &.devui-input-number-normal { - .devui-input-box{ - width: 80px; - height: 28px; - line-height: 28px; + &.devui-input-number-md { + width: 80px; + + .devui-input-box { + height: 32px; + line-height: 32px; } } &.devui-input-number-lg { - .devui-input-box{ - width: 80px; - height: 46px; - line-height: 46px; + width: 100px; + + .devui-input-box { + height: 38px; + line-height: 38px; } } diff --git a/packages/devui-vue/devui/input-number/src/input-number.tsx b/packages/devui-vue/devui/input-number/src/input-number.tsx index de60d57698..703611ee22 100644 --- a/packages/devui-vue/devui/input-number/src/input-number.tsx +++ b/packages/devui-vue/devui/input-number/src/input-number.tsx @@ -8,7 +8,7 @@ export default defineComponent({ props: inputNumberProps, emits: ['update:modelValue', 'change', 'input', 'focus', 'blur', 'keydown'], setup(props: InputNumberProps, ctx) { - const inputVal = ref(props.modelValue); + const inputVal = ref(props.modelValue < props.min ? props.min : props.modelValue); const focusVal = ref(''); @@ -26,7 +26,18 @@ export default defineComponent({ const add = () => { if (props.disabled) {return;} if (inputVal.value >= props.max) {return;} - inputVal.value += props.step != 0 ? props.step : 1; + if(props.step !== 0){ + const maxSpaceVal = props.max - inputVal.value; + if(inputVal.value < props.max && maxSpaceVal < props.step){ + inputVal.value += maxSpaceVal; + }else if(inputVal.value < props.max && maxSpaceVal > props.step){ + inputVal.value += props.step; + }else{ + inputVal.value += props.step; + } + }else{ + inputVal.value += 1; + } focusVal.value = 'active'; ctx.emit('change', inputVal.value); ctx.emit('update:modelValue', inputVal.value); @@ -35,15 +46,26 @@ export default defineComponent({ const subtract = () => { if (props.disabled) {return;} if (inputVal.value <= props.min) {return;} - inputVal.value -= props.step != 0 ? props.step : 1; + if(props.step !== 0){ + const minSpaceVal = inputVal.value - props.min; + if(inputVal.value > props.min && minSpaceVal > props.step){ + inputVal.value -= props.step; + }else if (inputVal.value > props.min && minSpaceVal < props.step){ + inputVal.value -= minSpaceVal; + }else{ + inputVal.value -= props.step; + } + }else{ + inputVal.value -= 1; + } focusVal.value = 'active'; ctx.emit('change', inputVal.value); ctx.emit('update:modelValue', inputVal.value); }; const onInput = (val) => { inputVal.value = parseInt(val.data); - ctx.emit('input', val.data); - ctx.emit('update:modelValue', val.data); + ctx.emit('input', inputVal.value); + ctx.emit('update:modelValue', inputVal.value); }; const onFocus = ($event: Event) => { focusVal.value = 'active'; @@ -91,9 +113,9 @@ export default defineComponent({ const dInputNum = ['devui-input-number', isDisabled ? 'devui-input-disabled' : '', isSize]; return (
-
- - +
+ +
- +
+ ``` ::: ### API @@ -125,7 +134,7 @@ import { defineComponent, ref } from 'vue' | min | `number` | -- | 可选,输入框的最小值min | [基本用法](#基本用法) | | disabled | `boolean` | false | 可选,文本框是否被禁用 | [禁用状态](#禁用状态) | | value | `number` | 0 | 可选,文本框默认值 | [基本用法](#基本用法) | -| size | `'lg'\|'normal'\|'sm'` | '' | 可选,文本框尺寸,有三种选择`'lg'`,`'narmal'`,`'sm'` | [尺寸](#尺寸) | +| size | `'lg'\|'md'\|'sm'` | '' | 可选,文本框尺寸,有三种选择`'lg'`,`'md'`,`'sm'` | [尺寸](#尺寸) | ### Events