Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #6047:InputNumber remove onKeyPress #6158

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading