Skip to content

Commit

Permalink
Merge pull request #6332 from melloware/PR6275-inputnumber
Browse files Browse the repository at this point in the history
Fix #6275: InputNumber restore Android usage
  • Loading branch information
gucal authored Apr 9, 2024
2 parents ff521c3 + 38aa102 commit ea2a8c5
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion components/lib/inputnumber/InputNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,38 @@ 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;
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 ea2a8c5

Please sign in to comment.