Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions packages/devui-vue/devui/input-number/src/input-number.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
38 changes: 30 additions & 8 deletions packages/devui-vue/devui/input-number/src/input-number.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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('');

Expand All @@ -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);
Expand All @@ -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';
Expand Down Expand Up @@ -91,9 +113,9 @@ export default defineComponent({
const dInputNum = ['devui-input-number', isDisabled ? 'devui-input-disabled' : '', isSize];
return (
<div class={dInputNum}>
<div onBlur={onBlur} tabindex="1" class={['devui-control-buttons', focusVal.value]}>
<span onClick={add}><Icon size="12px" name="chevron-up" ></Icon></span>
<span onClick={subtract}><Icon size="12px" name="chevron-down" ></Icon></span>
<div onBlur={onBlur} tabindex="1" class={['devui-control-buttons', focusVal.value]}>
<span onClick={add}><Icon size="12px" name="chevron-up" ></Icon></span>
<span onClick={subtract}><Icon size="12px" name="chevron-down" ></Icon></span>
</div>
<div class="devui-input-item">
<input
Expand Down
17 changes: 13 additions & 4 deletions packages/devui-vue/docs/components/input-number/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import { defineComponent, ref } from 'vue'
```vue
<template>
<div>
<d-input-number v-model="num" :step="2"></d-input-number>
<d-input-number v-model="num" :step="3"></d-input-number>
</div>
</template>
<script>
Expand All @@ -87,13 +87,16 @@ import { defineComponent, ref } from 'vue'

### 尺寸

:::demo 额外提供了 lg、normal、sm 三种尺寸的数字输入框。
:::demo 额外提供了 lg、md、sm 三种尺寸的数字输入框。

```vue
<template>
<div>
<div class="space">Large</div>
<d-input-number v-model="num1" :size="'lg'"></d-input-number>
<d-input-number v-model="num2" :size="'normal'"></d-input-number>
<div class="space">Middle</div>
<d-input-number v-model="num2" :size="'md'"></d-input-number>
<div class="space">Small</div>
<d-input-number v-model="num3" :size="'sm'"></d-input-number>
</div>
</template>
Expand All @@ -113,6 +116,12 @@ import { defineComponent, ref } from 'vue'
}
})
</script>
<style>
.space{
padding: 5px 0;
font-size: 16px;
}
</style>
```
:::
### API
Expand All @@ -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

Expand Down