Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function (event) {
const keyCode = event.keyCode
if (keyCode === ESCAPE_KEY_CODE) {
if (propagateEscapeKeyDown === false) {
event.stopPropagation()
}
inputElementRef.current.blur()
return
}
if (keyCode === DOWN_KEY_CODE || keyCode === UP_KEY_CODE) {
event.preventDefault()
const evaluatedValue = evaluateNumericExpression(value)
if (
(event.keyCode === DOWN_KEY_CODE && evaluatedValue <= minimum) ||
(event.keyCode === UP_KEY_CODE && evaluatedValue >= maximum)
) {
return
}
const delta = event.shiftKey === true ? bigIncrement : smallIncrement
const newValue =
event.keyCode === DOWN_KEY_CODE
? Math.max(evaluatedValue - delta, minimum)
: Math.min(evaluatedValue + delta, maximum)
const significantFiguresCount = countSignificantFigures(
nonDigitRegex.test(value) === true ? `${evaluatedValue}` : value
)
inputElementRef.current.value = formatSignificantFigures(
newValue,
nonDigitRegex.test(value) === true ? `${evaluatedValue}` : value
)
inputElementRef.current.value = formatSignificantFigures(
newValue,
significantFiguresCount
)
handleInput()
handleFocus()
return
}
if (event.ctrlKey === true || event.metaKey === true) {
return
}
if (isKeyCodeCharacterGenerating(event.keyCode) === true) {
const nextValue = computeNextValue(inputElementRef.current, event.key)
if (isValidNumericInput(nextValue, isInteger) === false) {
event.preventDefault()
return
}
const evaluatedValue = evaluateNumericExpression(nextValue)
if (evaluatedValue < minimum || evaluatedValue > maximum) {
event.preventDefault()
}
}
},
[
significantFiguresCount
)
handleInput()
handleFocus()
return
}
if (event.ctrlKey === true || event.metaKey === true) {
return
}
if (isKeyCodeCharacterGenerating(event.keyCode) === true) {
const nextValue = computeNextValue(inputElementRef.current, event.key)
if (isValidNumericInput(nextValue, isInteger) === false) {
event.preventDefault()
return
}
const evaluatedValue = evaluateNumericExpression(nextValue)
if (evaluatedValue < minimum || evaluatedValue > maximum) {
event.preventDefault()
}
}
},
[
function (event) {
const nextValue = computeNextValue(
inputElementRef.current,
event.clipboardData.getData('Text')
)
if (isValidNumericInput(nextValue, isInteger) === false) {
event.preventDefault()
}
},
[isInteger]