Skip to content

Commit

Permalink
feat(input-number): 支持透传属性至 input 元素 (#3008)
Browse files Browse the repository at this point in the history
  • Loading branch information
eiinu authored Apr 7, 2024
1 parent 1a16230 commit c36bc88
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ import { h, nextTick } from 'vue'
import { Left, Right } from '@nutui/icons-vue'

test('InputNumber: should render modelValue', () => {
const wrapper = mount(InputNumber, {
props: {
modelValue: 12
}
const wrapper = mount(() => {
return <InputNumber modelValue={12} />
})

const input = wrapper.find('input').element as HTMLInputElement
expect(input.value).toBe('12')
})
Expand Down Expand Up @@ -189,3 +186,15 @@ test('InputNumber: should change modelValue after props.min was changed', async
expect(wrapper.emitted()['update:modelValue']).toHaveLength(1)
expect(wrapper.emitted()['update:modelValue'][0]).toStrictEqual(['7', {}])
})

test('InputNumber: v-bind="$attrs"', async () => {
const testClass = 'test-attr-class'
const customAttr = 'custom-attr'
const wrapper = mount(() => {
return <InputNumber modelValue={12} class={testClass} custom-attr={customAttr} />
})

const input = wrapper.find('input').element as HTMLInputElement
expect(input.getAttribute('class')).includes(testClass)
expect(input.getAttribute(customAttr)).includes(customAttr)
})
4 changes: 4 additions & 0 deletions src/packages/__VUE/inputnumber/doc.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ Set step size `step` 0.1 `decimal places` keep 1 decimal place
| disabled | Disable all features | boolean | `false` |
| readonly | Read only status disables input box operation behavior | boolean | `false` |

### Attrs version

The attributes on `InputNumber` will be inherited by `input` element.

### Slots

| Name | Description |
Expand Down
4 changes: 4 additions & 0 deletions src/packages/__VUE/inputnumber/doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ app.use(InputNumber)
| disabled | 禁用所有功能 | boolean | `false` |
| readonly | 只读状态禁用输入框操作行为 | boolean | `false` |

### Attrs version

支持透传属性至组件内部的 input 元素。

### Slots

| 名称 | 说明 |
Expand Down
4 changes: 4 additions & 0 deletions src/packages/__VUE/inputnumber/doc.taro.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ app.use(InputNumber)
| disabled | 禁用所有功能 | boolean | `false` |
| readonly | 只读状态禁用输入框操作行为 | boolean | `false` |

### Attrs version

支持透传属性至组件内部的 input 元素。

### Slots

| 名称 | 说明 |
Expand Down
4 changes: 3 additions & 1 deletion src/packages/__VUE/inputnumber/input-number.taro.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
v-else
class="nut-input-number__text--input"
type="number"
v-bind="$attrs"
:min="min"
:max="max"
:style="{ width: pxCheck(inputWidth), height: pxCheck(buttonSize) }"
Expand Down Expand Up @@ -44,7 +45,8 @@ import { Minus, Plus } from '@nutui/icons-vue-taro'
import { useFormDisabled } from '../form/common'
defineOptions({
name: 'NutInputNumber'
name: 'NutInputNumber',
inheritAttrs: false
})
export type InputNumberProps = Partial<{
Expand Down
4 changes: 3 additions & 1 deletion src/packages/__VUE/inputnumber/input-number.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
</view>
<input
type="number"
v-bind="$attrs"
:min="min"
:max="max"
:style="{ width: pxCheck(inputWidth), height: pxCheck(buttonSize) }"
Expand Down Expand Up @@ -39,7 +40,8 @@ import { Minus, Plus } from '@nutui/icons-vue'
import { useFormDisabled } from '../form/common'
defineOptions({
name: 'NutInputNumber'
name: 'NutInputNumber',
inheritAttrs: false
})
export type InputNumberProps = Partial<{
Expand Down

0 comments on commit c36bc88

Please sign in to comment.