Skip to content

Commit 5afd9da

Browse files
authored
fix(react-spinbutton): slot input handler set value (#33680)
1 parent b929a86 commit 5afd9da

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "fix spinbutton test",
4+
"packageName": "@fluentui/react-spinbutton",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

packages/react-components/react-spinbutton/library/src/components/SpinButton/SpinButton.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ describe('SpinButton', () => {
554554
userEvent.click(decrementButton);
555555

556556
expect(onChange).toHaveBeenCalledTimes(2);
557-
expect(onChange.mock.calls[1][1]).toEqual({ value: -1, displayValue: undefined });
557+
expect(onChange.mock.calls[1][1]).toEqual({ value: 0, displayValue: undefined });
558558
});
559559

560560
it('calls on change when defaultValue is `null` with min when uncontrolled', () => {

packages/react-components/react-spinbutton/library/src/components/SpinButton/useSpinButton.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,13 @@ export const useSpinButton_unstable = (props: SpinButtonProps, ref: React.Ref<HT
154154
};
155155

156156
const handleIncrementMouseDown = (e: React.MouseEvent<HTMLButtonElement>) => {
157+
commit(e, currentValue, textValue);
157158
internalState.current.spinState = 'up';
158159
stepValue(e, 'up');
159160
};
160161

161162
const handleDecrementMouseDown = (e: React.MouseEvent<HTMLButtonElement>) => {
163+
commit(e, currentValue, textValue);
162164
internalState.current.spinState = 'down';
163165
stepValue(e, 'down');
164166
};
@@ -231,10 +233,12 @@ export const useSpinButton_unstable = (props: SpinButtonProps, ref: React.Ref<HT
231233
if (valueChanged) {
232234
roundedValue = precisionRound(newValue!, precision);
233235
setCurrentValue(roundedValue);
236+
internalState.current.value = roundedValue;
234237
} else if (displayValueChanged && !isControlled) {
235238
const nextValue = parseFloat(newDisplayValue as string);
236239
if (!isNaN(nextValue)) {
237240
setCurrentValue(precisionRound(nextValue, precision));
241+
internalState.current.value = precisionRound(nextValue, precision);
238242
}
239243
}
240244

@@ -323,6 +327,7 @@ export const useSpinButton_unstable = (props: SpinButtonProps, ref: React.Ref<HT
323327
state.input['aria-valuemax'] = max;
324328
state.input['aria-valuetext'] = state.input['aria-valuetext'] ?? ((value !== undefined && displayValue) || undefined);
325329
state.input.onChange = mergeCallbacks(state.input.onChange, handleInputChange);
330+
state.input.onInput = mergeCallbacks(state.input.onInput, handleInputChange);
326331
state.input.onBlur = mergeCallbacks(state.input.onBlur, handleBlur);
327332
state.input.onKeyDown = mergeCallbacks(state.input.onKeyDown, handleKeyDown);
328333
state.input.onKeyUp = mergeCallbacks(state.input.onKeyUp, handleKeyUp);

0 commit comments

Comments
 (0)