Skip to content

Commit aa450a6

Browse files
committed
Blur empty value
1 parent 52350b7 commit aa450a6

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

packages/mui-base/src/unstable_useNumberInput/numberInputReducer.test.ts

+25
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,31 @@ describe('numberInputReducer', () => {
108108
expect(result.value).to.equal(9);
109109
expect(result.inputValue).to.equal('9');
110110
});
111+
112+
it('empty value', () => {
113+
const state: NumberInputState = {
114+
value: '',
115+
inputValue: '',
116+
};
117+
118+
const action: NumberInputReducerAction = {
119+
type: NumberInputActionTypes.blur,
120+
event: {
121+
currentTarget: {
122+
value: '',
123+
},
124+
} as unknown as React.FocusEvent<HTMLInputElement>,
125+
context: {
126+
getInputValueAsString: defaultGetInputValueAsString,
127+
shiftMultiplier: 10,
128+
},
129+
};
130+
131+
const result = numberInputReducer(state, action);
132+
133+
expect(result.value).to.equal('');
134+
expect(result.inputValue).to.equal('');
135+
});
111136
});
112137

113138
describe('action: inputChange', () => {

packages/mui-base/src/unstable_useNumberInput/numberInputReducer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { clamp, isNumber } from './utils';
1111
function getClampedValues(rawValue: number | undefined, context: NumberInputActionContext) {
1212
const { min, max, step } = context;
1313

14-
const clampedValue = rawValue === undefined ? undefined : clamp(rawValue, min, max, step);
14+
const clampedValue = rawValue === undefined ? '' : clamp(rawValue, min, max, step);
1515

1616
const newInputValue = clampedValue === undefined ? '' : String(clampedValue);
1717

0 commit comments

Comments
 (0)