Skip to content

Commit

Permalink
Fix #6275: InputNumber restore Android usage
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Apr 8, 2024
1 parent 131e680 commit 38aa102
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions components/lib/inputnumber/InputNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,44 @@ export const InputNumber = React.memo(
isSpecialChar.current = false;
};

const onInputAndroidKey = (event) => {
if (!DomHandler.isAndroid() || 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;

if (code !== 13) {
// to submit a form
event.preventDefault();
}

const char = String.fromCharCode(code);
const _isDecimalSign = isDecimalSign(char);
const _isMinusSign = isMinusSign(char);

if ((48 <= code && code <= 57) || _isMinusSign || _isDecimalSign) {
insert(event, char, { isDecimalSign: _isDecimalSign, isMinusSign: _isMinusSign });
} else {
updateValue(event, event.target.value, null, 'delete-single');
}
};

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

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

return;
Expand All @@ -340,6 +372,11 @@ export const InputNumber = React.memo(

lastValue.current = event.target.value;

// Android is handled specially in onInputAndroidKey
if (DomHandler.isAndroid()) {
return;
}

let selectionStart = event.target.selectionStart;
let selectionEnd = event.target.selectionEnd;
let inputValue = event.target.value;
Expand Down Expand Up @@ -430,7 +467,6 @@ export const InputNumber = React.memo(
newValueStr = deleteRange(inputValue, selectionStart, selectionEnd);
updateValue(event, newValueStr, null, 'delete-range');
}

break;

// del
Expand Down Expand Up @@ -1123,6 +1159,7 @@ export const InputNumber = React.memo(
name={props.name}
autoFocus={props.autoFocus}
onKeyDown={onInputKeyDown}
onKeyPress={onInputAndroidKey}
onInput={onInput}
onClick={onInputClick}
onPointerDown={onInputPointerDown}
Expand Down

0 comments on commit 38aa102

Please sign in to comment.