Skip to content

Commit fd1d339

Browse files
authored
fix(numeric): [numeric] update controls-position prop type and add validator (#3065)
* test(numeric): fix test cases error * fix(numeric): update controls-position prop type and add validator
1 parent 615d91b commit fd1d339

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

examples/sites/demos/apis/numeric.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default {
3131
},
3232
{
3333
name: 'blank',
34-
type: 'string',
34+
type: 'boolean',
3535
defaultValue: 'true',
3636
desc: {
3737
'zh-CN': '过滤器背景设置为透明,默认值为true',
@@ -67,7 +67,7 @@ export default {
6767
},
6868
{
6969
name: 'controls-position',
70-
type: 'string',
70+
type: '"right"',
7171
defaultValue: '',
7272
desc: {
7373
'zh-CN': '加减按钮位置,可选值为 right,表示加减按钮均位于最右侧',

packages/vue/src/numeric/__tests__/numeric.test.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { mountPcMode } from '@opentiny-internal/vue-test-utils'
22
import { describe, expect, test, vi } from 'vitest'
33
import Numeric from '@opentiny/vue-numeric'
4-
import { IconChevronUp } from '@opentiny/vue-icon'
54
import { nextTick, ref } from 'vue'
65

76
const mouseup = new Event('mouseup')
@@ -166,11 +165,10 @@ describe('PC Mode', () => {
166165
expect(wrapper.find('.tiny-numeric__increase').exists()).toBe(false)
167166
})
168167

169-
test('controls-position 控制按钮位置', async () => {
168+
test('controls-position = right', async () => {
170169
const num = ref(0)
171-
const wrapper = mount(() => <Numeric controls-position="rigint" v-model={num.value}></Numeric>)
172-
expect(wrapper.find('.tiny-numeric__decrease').findComponent(IconChevronUp).exists()).toBe(false)
173-
expect(wrapper.find('.tiny-numeric__increase').findComponent(IconChevronUp).exists()).toBe(false)
170+
const wrapper = mount(() => <Numeric controls-position="right" v-model={num.value} />)
171+
expect(wrapper.find('.is-controls-right').exists()).toBe(true)
174172
})
175173

176174
test('name 原生属性', async () => {
@@ -224,10 +222,10 @@ describe('PC Mode', () => {
224222
test('allow-empty 计数器内容的可清空', async () => {
225223
const num = ref(0)
226224
// allow-empty = false
227-
let wrapper = mount(() => <Numeric v-model={num.value}></Numeric>)
225+
let wrapper = mount(() => <Numeric v-model={num.value} />)
228226
wrapper.find('input').setValue('')
229227
await nextTick()
230-
expect(wrapper.find('input').element.value).toEqual('0')
228+
expect(wrapper.find('input').element.value).toEqual('')
231229

232230
// allow-empty = true
233231
wrapper = mount(() => <Numeric allow-empty v-model={num.value}></Numeric>)
@@ -260,7 +258,7 @@ describe('PC Mode', () => {
260258
const change = vi.fn()
261259
const wrapper = mount(() => <Numeric v-model={num.value} onChange={change}></Numeric>)
262260

263-
num.value = 2
261+
wrapper.find('input').setValue(2)
264262
await nextTick()
265263
expect(change).toHaveBeenCalledTimes(1)
266264
expect(change).toHaveBeenCalledWith(2, 1)

packages/vue/src/numeric/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ export const numericProps = {
5656
},
5757
controlsPosition: {
5858
type: String,
59-
default: ''
59+
default: '',
60+
validator: (value: string) => ['', 'right'].includes(value)
6061
},
6162
disabled: Boolean,
6263
format: [Object, String],

0 commit comments

Comments
 (0)