forked from opentiny/tiny-vue
fix(numeric): [numeric] Fix Bug caused by initial value greater than maximum (#1284)
* fix(numeric): Fix Bug caused by initial value greater than maximum * fix(numeric): Fix Bug caused by initial value greater than maximum * fix(numeric): Fix Bug caused by initial value greater than maximum
This commit is contained in:
parent
f6257a7374
commit
34e5916278
|
@ -11,10 +11,10 @@ export default {
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
value: 1,
|
value: 0,
|
||||||
step: 2,
|
step: 2,
|
||||||
min: 0,
|
min: 0,
|
||||||
max: 5
|
max: 10
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,6 @@ export const watchValue =
|
||||||
if (value === state.currentValue) {
|
if (value === state.currentValue) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
api.setCurrentValue(value)
|
api.setCurrentValue(value)
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
api.dispatchDisplayedValue()
|
api.dispatchDisplayedValue()
|
||||||
|
@ -355,8 +354,17 @@ export const select = (refs: INumericRenderlessParams['refs']) => () => refs.inp
|
||||||
export const mounted =
|
export const mounted =
|
||||||
({ constants, parent, props, state }: Pick<INumericRenderlessParams, 'constants' | 'parent' | 'props' | 'state'>) =>
|
({ constants, parent, props, state }: Pick<INumericRenderlessParams, 'constants' | 'parent' | 'props' | 'state'>) =>
|
||||||
(): void => {
|
(): void => {
|
||||||
const innerInput = parent.$el.querySelector('input')
|
if (state.currentValue < (props.min as number)) {
|
||||||
|
state.currentValue = props.min as number
|
||||||
|
state.lastInput = props.min as number
|
||||||
|
state.userInput = props.min as number
|
||||||
|
}
|
||||||
|
if (state.currentValue > (props.max as number)) {
|
||||||
|
state.currentValue = props.max as number
|
||||||
|
state.lastInput = props.max as number
|
||||||
|
state.userInput = props.max as number
|
||||||
|
}
|
||||||
|
const innerInput = parent.$el.querySelector('input')!
|
||||||
innerInput.setAttribute(constants.KEY, constants.VALUE)
|
innerInput.setAttribute(constants.KEY, constants.VALUE)
|
||||||
innerInput.setAttribute(constants.MAX, props.max)
|
innerInput.setAttribute(constants.MAX, props.max)
|
||||||
innerInput.setAttribute(constants.MIN, props.min)
|
innerInput.setAttribute(constants.MIN, props.min)
|
||||||
|
|
|
@ -67,6 +67,7 @@ describe('PC Mode', () => {
|
||||||
test('min 规定组件可输入的最小数值', async () => {
|
test('min 规定组件可输入的最小数值', async () => {
|
||||||
const inputValue = ref(1)
|
const inputValue = ref(1)
|
||||||
const wrapper = mount(() => <Numeric v-model={inputValue.value} min={3}></Numeric>)
|
const wrapper = mount(() => <Numeric v-model={inputValue.value} min={3}></Numeric>)
|
||||||
|
await nextTick()
|
||||||
expect(wrapper.find('input').element.value).toEqual('3')
|
expect(wrapper.find('input').element.value).toEqual('3')
|
||||||
wrapper.find('.tiny-numeric__decrease').trigger('mousedown')
|
wrapper.find('.tiny-numeric__decrease').trigger('mousedown')
|
||||||
document.dispatchEvent(mouseup)
|
document.dispatchEvent(mouseup)
|
||||||
|
@ -77,6 +78,7 @@ describe('PC Mode', () => {
|
||||||
test('max 规定组件可输入的最大数值', async () => {
|
test('max 规定组件可输入的最大数值', async () => {
|
||||||
const inputValue = ref(6)
|
const inputValue = ref(6)
|
||||||
const wrapper = mount(() => <Numeric v-model={inputValue.value} max={3}></Numeric>)
|
const wrapper = mount(() => <Numeric v-model={inputValue.value} max={3}></Numeric>)
|
||||||
|
await nextTick()
|
||||||
expect(wrapper.find('input').element.value).toEqual('3')
|
expect(wrapper.find('input').element.value).toEqual('3')
|
||||||
wrapper.find('.tiny-numeric__increase').trigger('mousedown')
|
wrapper.find('.tiny-numeric__increase').trigger('mousedown')
|
||||||
document.dispatchEvent(mouseup)
|
document.dispatchEvent(mouseup)
|
||||||
|
|
Loading…
Reference in New Issue