diff --git a/components/lib/calendar/Calendar.js b/components/lib/calendar/Calendar.js index f96025de87..27f4577d7b 100644 --- a/components/lib/calendar/Calendar.js +++ b/components/lib/calendar/Calendar.js @@ -127,6 +127,16 @@ export const Calendar = React.memo( }; const onInputKeyDown = (event) => { + // Should Intercept letters and other invalid characters before they're inserted. + const allowedKeys = ['Backspace', 'Delete', 'Tab', 'Escape', 'Enter', 'NumpadEnter', 'ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Home', 'End', 'PageUp', 'PageDown']; + const allowedCharsRegex = /^[0-9\/\-\.\s:,]$/; + + if (!allowedKeys.includes(event.key) && !allowedCharsRegex.test(event.key) && !event.ctrlKey && !event.metaKey) { + event.preventDefault(); + + return; + } + switch (event.code) { case 'ArrowDown': { if (!overlayVisibleState) {