Skip to content

Commit

Permalink
Improve onKeyPress clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed Oct 10, 2021
1 parent 91a1619 commit cc5f22e
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/DateInput/Input.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,12 @@ function makeOnKeyPress(maxLength) {
const { key, target: input } = event;
const { value } = input;

const isNumberKey = !isNaN(parseInt(key, 10));
const isNumberKey = key.length === 1 && /\d/.test(key);
const selection = getSelectionString(input);

if (isNumberKey && (selection || value.length < maxLength)) {
return;
if (!isNumberKey || !(selection || value.length < maxLength)) {
event.preventDefault();
}

event.preventDefault();
};
}

Expand Down

0 comments on commit cc5f22e

Please sign in to comment.