Skip to content

Commit

Permalink
Fix #6047:InputNumber remove onKeyPress (#6158)
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware authored Mar 15, 2024
1 parent f233199 commit cc96020
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 44 deletions.
54 changes: 15 additions & 39 deletions components/lib/inputnumber/InputNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ export const InputNumber = React.memo(
return;
}

if (event.shiftKey || event.altKey) {
isSpecialChar.current = true;

return;
}

if (props.onKeyDown) {
props.onKeyDown(event);

Expand All @@ -333,21 +339,11 @@ export const InputNumber = React.memo(

lastValue.current = event.target.value;

if (event.shiftKey || event.altKey) {
isSpecialChar.current = true;

return;
}

let selectionStart = event.target.selectionStart;
let selectionEnd = event.target.selectionEnd;
let inputValue = event.target.value;
let newValueStr = null;

if (event.altKey) {
event.preventDefault();
}

switch (event.code) {
//up
case 'ArrowUp':
Expand Down Expand Up @@ -379,6 +375,7 @@ export const InputNumber = React.memo(

//enter and tab
case 'Tab':
case 'NumpadEnter':
case 'Enter':
newValueStr = validateValue(parseValue(inputValue));
inputRef.current.value = formatValue(newValueStr);
Expand Down Expand Up @@ -494,37 +491,17 @@ export const InputNumber = React.memo(
break;

default:
break;
}
};

const onInputKeyUp = (event) => {
if (props.disabled || props.readOnly) {
return;
}

if (props.onKeyUp) {
props.onKeyUp(event);

// do not continue if the user defined event wants to prevent
if (event.defaultPrevented) {
return;
}
}

const code = event.which || event.keyCode;
event.preventDefault();

if (code !== 13) {
// to submit a form
event.preventDefault();
}
let char = event.key;
const _isDecimalSign = isDecimalSign(char);
const _isMinusSign = isMinusSign(char);

const char = String.fromCharCode(code);
const _isDecimalSign = isDecimalSign(char);
const _isMinusSign = isMinusSign(char);
if (((event.code.startsWith('Digit') || event.code.startsWith('Numpad')) && Number(char) >= 0 && Number(char) <= 9) || _isMinusSign || _isDecimalSign) {
insert(event, char, { isDecimalSign: _isDecimalSign, isMinusSign: _isMinusSign });
}

if ((48 <= code && code <= 57) || _isMinusSign || _isDecimalSign) {
insert(event, char, { isDecimalSign: _isDecimalSign, isMinusSign: _isMinusSign });
break;
}
};

Expand Down Expand Up @@ -1137,7 +1114,6 @@ export const InputNumber = React.memo(
name={props.name}
autoFocus={props.autoFocus}
onKeyDown={onInputKeyDown}
onKeyPress={onInputKeyUp}
onInput={onInput}
onClick={onInputClick}
onPointerDown={onInputPointerDown}
Expand Down
5 changes: 0 additions & 5 deletions components/lib/inputnumber/inputnumber.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,6 @@ export interface InputNumberProps extends Omit<React.DetailedHTMLProps<React.HTM
* @param {React.KeyboardEvent<HTMLInputElement>} event - Browser event
*/
onKeyDown?(event: React.KeyboardEvent<HTMLInputElement>): void;
/**
* Callback to invoke when the key released.
* @param {React.KeyboardEvent<HTMLInputElement>} event - Browser event
*/
onKeyUp?(event: React.KeyboardEvent<HTMLInputElement>): void;
/**
* Used to get the child elements of the component.
* @readonly
Expand Down

0 comments on commit cc96020

Please sign in to comment.