@s-ui/react-atom-input
Version:
> Inputs are the text fields that users fill in with different types of information. These include dates, passwords or even short answers. It’s a field where users can write alphanumeric texts.
16 lines (15 loc) • 774 B
JavaScript
import { TYPES } from '../config.js';
export default (function (event, _ref) {
var type = _ref.type,
onEnterKey = _ref.onEnterKey;
if (type === TYPES.NUMBER) {
// Check if input type number is valid as input type number doesn't currently work in browsers like Safari and Firefox
// Allowing: Integers | Backspace | Tab | Delete | Left & Right arrow keys
// const allowedCharacter =
// /(^\d*$)|(Backspace|Tab|Delete|ArrowLeft|ArrowRight|Enter)/
var onEnterKeyArray = Array.isArray(onEnterKey) ? onEnterKey : [onEnterKey];
var allowedCharacter = new RegExp("(^\\d*$)|(" + ['Backspace', 'Tab', 'Delete', 'ArrowLeft', 'ArrowRight'].concat(onEnterKeyArray).join('|') + ")");
return event.key.match(allowedCharacter);
}
return true;
});