fix(components):[numeric]Fixed a bug where manually entering values does not change according to step after fixing the stepStrictly property setting (#1003)

* feat(tree-menu):The placeholder of the search box can be customized

* fix(numeric):Fixed a bug where manually entering values does not change according to step after fixing the stepStrictly property setting

* +Change to Number

* fix(components):[numeric]+ change to Number

* fix(components):[numeric]+ change to Number

* fix(components):[numeric]modify logic
This commit is contained in:
fanbingbing16 2024-01-03 10:55:17 +08:00 committed by GitHub
parent 723b07d0ee
commit 01c39cde52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 5 deletions

View File

@ -336,11 +336,18 @@ export const handleInput =
}
export const handleInputChange =
({ api }: Pick<INumericRenderlessParams, 'api'>) =>
({ api, state, props }: Pick<INumericRenderlessParams, 'api' | 'state' | 'props'>) =>
(event: Event): void => {
const value = event.target.value
api.setCurrentValue(value === '-' ? 0 : value)
const value = event.target?.value === '-' ? 0 : event.target?.value
if (props.stepStrictly) {
const previousValue = Number((props.mouseWheel ? state.displayValue : props.modelValue) || 0)
if (Math.abs(previousValue - value) % Number(props.step) === 0) return api.setCurrentValue(value)
const step = Number(props.step)
const difference = value - previousValue
const sign = difference >= 0 ? 1 : -1
return api.setCurrentValue(sign * Math.round(Math.abs(difference) / step) * step + previousValue)
}
api.setCurrentValue(value)
}
export const select = (refs: INumericRenderlessParams['refs']) => () => refs.input.select()

View File

@ -122,7 +122,7 @@ const initApi = ({
displayValue: displayValue({ props, state }),
internalDecrease: internalDecrease({ api, state }),
internalIncrease: internalIncrease({ api, state }),
handleInputChange: handleInputChange({ api }),
handleInputChange: handleInputChange({ api, state, props }),
mouseEvent: mouseEvent({ api, props, state }),
handleBlur: handleBlur({ constants, dispatch, emit, props, state, api }),
watchValue: watchValue({ api, state, nextTick }),