Skip to content

Commit

Permalink
Merge pull request #273 from arco-design/fix-stepper-value
Browse files Browse the repository at this point in the history
fix: `stepper` controlled value
  • Loading branch information
shenhaidada authored Jun 26, 2024
2 parents f081b14 + 4f8d060 commit 2325a7a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default function useInputEvent(
params: Required<Pick<StepperProps, 'defaultValue' | 'min' | 'max' | 'digits' | 'allowEmpty'>> &
Pick<StepperProps, 'onBlur' | 'onChange' | 'onInput'> & {
actualInputValue: number;
innerValue: number;
updateValue: (updater: number | ((oldValue: number) => number)) => void;
},
) {
Expand All @@ -15,6 +16,7 @@ export default function useInputEvent(
max,
digits,
actualInputValue,
innerValue,
allowEmpty,
updateValue,
onBlur,
Expand Down Expand Up @@ -53,8 +55,8 @@ export default function useInputEvent(
};

useUpdateEffect(() => {
onChange && onChange(actualInputValue);
}, [actualInputValue]);
onChange && onChange(innerValue);
}, [innerValue]);

return {
handleInput,
Expand Down
1 change: 1 addition & 0 deletions packages/arcodesign/components/stepper/hooks/useValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ export default function useValue(
updateValue,
actualInputValue,
showValue,
innerValue,
};
}
3 changes: 2 additions & 1 deletion packages/arcodesign/components/stepper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const Stepper = forwardRef((props: StepperProps, ref: Ref<StepperRef>) => {

// 值的相关逻辑
// @en The logic is that handle value
const { updateValue, actualInputValue, showValue } = useValue({
const { updateValue, actualInputValue, showValue, innerValue } = useValue({
defaultValue,
formatter,
min,
Expand Down Expand Up @@ -75,6 +75,7 @@ const Stepper = forwardRef((props: StepperProps, ref: Ref<StepperRef>) => {
digits,
actualInputValue,
allowEmpty,
innerValue,
updateValue,
onBlur,
onChange,
Expand Down
2 changes: 1 addition & 1 deletion packages/arcodesign/tokens/app/arcodesign/default/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exports["default"] = void 0;
exports.getRem = getRem;

function getRem(px, baseFontSize) {
var num = Math.round(px / Number(baseFontSize) * 1000000) / 1000000;
var num = Math.round(px / Number(baseFontSize) * 1e6) / 1e6;
return num ? "".concat(num, "rem") : num;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/arcodesign/tokens/mixin/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
* @param @rules {en} customized rewrite rules, default to initial
* @example
* ```
* @import '@arco-design/mobile-utils/style/mixin.less';
* @import '@arco-design/mobile-react/style/mixin.less';
*
* .demo {
* .set-prop-with-rtl(right, auto);
Expand All @@ -183,7 +183,7 @@
* @param @value {en} css property value
* @example
* ```
* @import '@arco-design/mobile-utils/style/mixin.less';
* @import '@arco-design/mobile-react/style/mixin.less';
*
* .demo {
* .set-value-with-rtl(text-align, left);
Expand Down

0 comments on commit 2325a7a

Please sign in to comment.